官网:https://www.wangeditor.com/
导入:
- npm 安装
npm i wangeditor --save
,几行代码即可创建一个编辑器。 - 导入wangeditor编辑器
import E from 'wangeditor'
- 编写代码
<div id="div1"></div>
methods: {
creatDom(){
editor = new E('#div1');//富文本编辑器创建,获取节点
// 配置 server 接口地址
/*editor.config.uploadImgServer = 'http://localhost:9090/files/editor/upload';
editor.config.uploadFileName = 'file';//设置文件上传的名字*/
editor.create();//创建。
},
handleAdd() {
this.dialogFormVisible = true
this.form = {}
if (!editor){
this.$nextTick(()=>{
if (editor==null){
this.creatDom();
}else {
editor.destroy();//这里做了一次判断,判断编辑器是否被创建,如果创建了就先销毁。
this.creatDom();
}
});
}
},
},
handleEdit(row) {
this.form = JSON.parse(JSON.stringify(row))
this.dialogFormVisible = true
this.$nextTick(()=>{
if (editor==null){
this.creatDom();
editor.txt.html(row.content);
}else {
editor.destroy();//这里做了一次判断,判断编辑器是否被创建,如果创建了就先销毁。
this.creatDom();
editor.txt.html(row.content);
}
});
}
Q.E.D.