<template>
<div>
<div style="border: 1px solid #ccc; width: 500px">
<!-- 工具栏 -->
<Toolbar style="border-bottom: 1px solid #ccc" :editor="editor" :defaultConfig="toolbarConfig" />
<!-- 编辑器 -->
<Editor style="height: 400px; overflow-y: hidden" :defaultConfig="editorConfig" v-model="html" @onChange="onChange" @onCreated="onCreated" />
</div>
</div>
</template> <script>
import { Editor, Toolbar } from '@wangeditor/editor-for-vue';
import Cookie from 'js-cookie'; export default {
name: 'MyEditor',
components: { Editor, Toolbar },
props: {
destDir: {
type: String,
},
},
data() {
return {
editor: null,
html: '',
toolbarConfig: {
// toolbarKeys: [ /* 显示哪些菜单,如何排序、分组 */ ],
// excludeKeys: [ /* 隐藏哪些菜单 */ ],
},
editorConfig: {
placeholder: '请输入内容...',
// autoFocus: false, // 所有的菜单配置,都要在 MENU_CONF 属性下
MENU_CONF: {},
},
};
},
methods: {
onCreated(editor) {
this.editor = Object.seal(editor); // 【注意】一定要用 Object.seal() 否则会报错
console.log('Created');
},
onChange(editor) {
// console.log('onChange', editor.getHtml()); // onChange 时获取编辑器最新内容
}, loadHtml(html) {
this.html = html;
},
insertTextHandler(html) {
const editor = this.editor;
if (editor == null) return;
console.log(html);
editor.insertText(html);
},
printEditorHtml() {
const editor = this.editor;
if (editor == null) return;
console.log(editor.getHtml());
},
disableHandler() {
const editor = this.editor;
if (editor == null) return;
editor.disable();
},
// 自定义校验图片
customCheckImageFn(src, alt, url) {
if (!src) {
return;
}
if (src.indexOf('http') !== 0) {
return '图片网址必须以 http/https 开头';
}
return true; // 返回值有三种选择:
// 1. 返回 true ,说明检查通过,编辑器将正常插入图片
// 2. 返回一个字符串,说明检查未通过,编辑器会阻止插入。会 alert 出错误信息(即返回的字符串)
// 3. 返回 undefined(即没有任何返回),说明检查未通过,编辑器会阻止插入。但不会提示任何信息
}, // 转换图片链接
customParseImageSrc(src) {
// JS 语法
if (src.indexOf('http') !== 0) {
return `${this.pictureUrl}${src}`;
}
return src;
},
},
created() {
let that = this;
this.editorConfig.MENU_CONF['uploadImage'] = {
server: process.env.VUE_APP_API_MANAGE + '/uploadFileController/editUpload.do',
fieldName: 'file',
// 继续写其他配置...
meta: {
destDir: that.destDir,
},
headers: {
adminToken: Cookie.get('adminToken'),
},
onSuccess(file, res) {
// JS 语法
console.log(`${file.name} 上传成功`, res);
},
// customInsert(res: any, insertFn: InsertFnType) {
// TS 语法
customInsert(res, insertFn) {
// JS 语法
// res 即服务端的返回结果
// 从 res 中找到 url alt href ,然后插入图片
insertFn(process.env.VUE_APP_SERVER + 'imageServer' + res.data.url, res.data.alt, res.data.href);
},

}; // 插入图片
this.editorConfig.MENU_CONF['insertImage'] = {
onInsertedImage(imageNode) {
// JS 语法
if (imageNode == null) return; const { src, alt, url, href } = imageNode;
console.log('inserted image', src, alt, url, href);
},
checkImage: that.customCheckImageFn, // 也支持 async 函数
parseImageSrc: that.customParseImageSrc, // 也支持 async 函数
};
},
mounted() {
// // 模拟 ajax 请求,异步渲染编辑器
// setTimeout(() => {
// this.html = '<p>Ajax 异步设置内容 HTML</p>';
// }, 1500);
},
beforeDestroy() {
const editor = this.editor;
if (editor == null) return;
editor.destroy(); // 组件销毁时,及时销毁 editor ,重要!!!
},
};
</script>
<style>
.w-e-full-screen-container {
bottom: 0 !important;
display: flex !important;
flex-direction: column !important;
height: 100% !important;
left: 0 !important;
margin: 0 !important;
padding: 0 !important;
position: fixed;
right: 0 !important;
top: 0 !important;
width: 100% !important;
z-index: 99999;
}
</style>
<style src="@wangeditor/editor/dist/css/style.css"></style>

vue富文本(5版本)组件的更多相关文章

  1. vue+富文本编辑器UEditor

    vue+富文本编辑器UEditor 昨天的需求是把textarea换成富文本编辑器的形式, 网上找了几种富文本编辑器ueditor.tinymce等, 觉得ueditor实现双向绑定还挺有意思, 分享 ...

  2. vue富文本vue-quill-editor

    这个富文本需要装一下插件 "quill": "^1.3.6" "quill-image-drop-module": "^1.0.3 ...

  3. vue富文本编辑器vue-quill-editor使用总结(包含图片上传,拖拽,放大和缩小)

    vue-quill-editor是vue很好的富文本编辑器,富文本的功能基本上都支持,样式是黑白色,简洁大方. 第一步下载 vue-quill-editor: npm i vue-quill-edit ...

  4. vue 富文本编辑器 项目实战用法

    1.挑个富文本编辑器 首先针对自己项目的类型,确定自己要用啥编辑器. 1.1 wangeditor 如果一般类似博客这种项目不需要花里胡哨的,功能也不要求贼多的,推荐一下wangeditor(点击跳转 ...

  5. Vue富文本编辑器(图片拖拽缩放)

    富文本编辑器(图片拖拽缩放) 需求: 根据业务要求,需要能够上传图片,且上传的图片能在移动端中占满屏幕宽度,故需要能等比缩放上传的图片,还需要能拖拽.缩放.改变图片大小.尝试多个第三方富文本编辑器,很 ...

  6. vue富文本编辑器vue-quill-editor

    1.下载Vue-Quill-Editor npm install vue-quill-editor --save 2.下载quill(Vue-Quill-Editor需要依赖) npm install ...

  7. vue富文本编辑器

    基于webpack和vue 一.npm 安装 vue-quill-editor 二.在main.js中引入 import VueQuillEditor from 'vue-quill-editor'/ ...

  8. 富文本编辑器quill---vue组件(vue-quill-editor)的使用

    1.配置webpack plugin 解决以下报错 Uncaught TypeError: Cannot read property 'imports' of undefined (image-res ...

  9. 前端富文本 js 版本

    https://s3.pstatp.com/pgc/v2/resource/tt_ueditor_v3_temple/tt-editor.all.js?20180425

  10. 适用于 Mpvue 的微信小程序富文本解析自定义组件

    废话不多说,直接上方法: 首先 npm 安装 mpvue-wxparse npm i mpvue-wxparse 接下来:使用 <template> <div> <wxP ...

随机推荐

  1. PCA降维练习

    [题目] 1.现有我国大陆30个省.直辖市.自治区的经济发展状况数据集如表所示,包括8项经济指标:国民生产总值(A1):居民消费水平(A2):固定资产投资(A3):职工平均工资(A4):货物周转量(A ...

  2. iOS证书签名

    苹果官方有一对密钥,即私钥和公钥,私钥在苹果后台,公钥在iOS系统中(如iPhone手机在出厂后,其中就保存有苹果官方的公钥):在Mac系统打包app时也会生成一对密钥(私钥.公钥),并保存在钥匙串中 ...

  3. vue 使用 swiper vue-awesome-swiper

    文档地址 https://github.com/surmon-china/vue-awesome-swiper 演示地址 https://v1.github.surmon.me/vue-awesome ...

  4. 最简单的asp验证码

    <%Public Function BornVerifyCode()         Randomize '设置随机因子         BornVerifyCode=Mid((Rnd * 10 ...

  5. chrome浏览器通知与语音播放

    HTML5 Web Notification 语法 https://developer.mozilla.org/zh-CN/docs/Web/API/notification 如果浏览器支持Web N ...

  6. Vue后台管理项目中解决需要配置多个端口号问题

    背景 登录接口:http://39.98.123.211:8170/ 商品接口:http://39.98.123.211:8510/ 可见前面是地址是一致的,但是端口号不一样. 这就会导致,登录进得去 ...

  7. 对象转Map

    Map<String, Object> userMap = BeanUtil.beanToMap(userDTO);

  8. Screw数据库文档生成神器

    引入依赖 <dependency> <groupId>cn.smallbun.screw</groupId> <artifactId>screw-cor ...

  9. mongoDB日常操作01

    //serialno_info.i,查看历史最大值db.serialno_info.find({'_id':'define_picture'})//查看文件记录有序id条数db.fs.files.fi ...

  10. 检测sqlserver数据库是否能远程连通

    建立一个.udl的文件夹,双击打开.输入相关的连接字符串点击测试即可.