坑了好几个小时这个问题
首先是在Dialog组件中显示富文本的问题
一开始一直在Dialog组件中使用new E(this.$refs.editor)
来进行初始化,发现一直失败,后来发现原来Dialog在没有显示的时候这个DOM是没有加载的,输出this.$refs.editor
发现确实是undefined
,所以在Dialog组件上添加@opened
事件,这时候就可以获取到这个this.$refs.editor
的DOM了这时候就可以初始化成功了。
Dialog上的绑定
<el-dialog
@opened="show()"
@closed="hide()"
/>
@opened
的代码,我这里是把DOM中的一些信息保存了下来
show() {
this.editor = new E(this.$refs.editor)
this.editor.customConfig.zIndex = 10
this.editor.customConfig.onchange = (html) => {
console.log('html', html)
}
this.editor.create()
}
接着就是多次点击循环嵌套显示的问题了,在Dialog的组件上添加@closed
事件
@closed
的代码,主要就是把那个DOM给去除了就可以了
hide() {
this.$refs.editor.innerHTML = ''
this.editor = null
}