vue中使用ueditor初始化时最好使用组件vue-ueditor-wrap,下载的ueditor文件夹直接放在public文件夹下。
安装好vue-ueditor-wrap后,需要在main.js中注册
import VueUeditorWrap from 'vue-ueditor-wrap'
window.commonComponent = { VueUeditorWrap };
以上步骤可在页面中初始化出编辑器。
但是在分布式系统中使用ueditor,会出现编辑器无法编辑,F12中报错"$EDITORUI is not defined",at HTMLDivElement.onmouseover(或onmouseout)。这个问题常规方式查找时需要引用jquery,引用的jquery,还是没有解决以上问题。并且网上也找不到相关问题的解决方案。
方案一:
页面的mounted中加载setClass()方法:
setClass() {
let myDiv = document.getElementById('edui_fixedlayer');
let clasName = document.getElementsByClassName("v-modal");
this.setInt1 = setInterval(() => {
if (myDiv != null) {
if (myDiv.style.zIndex != '999999') {
myDiv.style.zIndex = "999999"
}
}
//console.log(this.setInt1);
}, 200)
this.setInt2 = setInterval(() => {
if (clasName != null && clasName.length > 0) {
if (clasName[0].style.zIndex != 9) {
clasName[0].style.zIndex = 9
}
}
}, 1000)
},
最后看到同事解决了,是编辑器被挡住了。设置ueditor在最外层。就能正常编辑。
方案二:
qiankun前端框架主应用和子应用的情况。把ueditor文件夹直接放在主应用的public文件夹里。发布后的直接放在根目录,与index.html同级。
主应用同样需要安装vue-ueditor-wrap组件后,需要在main.js中注册
import VueUeditorWrap from 'vue-ueditor-wrap'
window.commonComponent = { VueUeditorWrap };
在子应用中,同样安装了vue-ueditor-wrap,子应用也放置了ueditor文件夹。但是编辑器无法使用,使用以下方法在页面初始化中,可以使编辑器可以编辑。
setEnable(){
//this.$refs.myueditor.setEnabled()
document.getElementById('ueditor_0').contentWindow.document.getElementsByTagName('body')[0].contentEditable = true
},
setDisable(){
//this.$refs.myueditor.setDisabled()
document.getElementById('ueditor_0').contentWindow.document.getElementsByTagName('body')[0].contentEditable = false
}
用这个方式有个问题,我的编辑器的工具栏无法使用,鼠标移上去还是报错。F12分析页面dom结构,发现ueditor的js引用都被注释掉了。出现<!-- <script dynamic type="text/javascript" charset="utf-8" src="ueditor.config.js"></script> replace by qiankun-->
找网上的资料,说是子应用的使用方式不对,调整组件引用
components: {
VueUeditorWrap: window.__POWERED_BY_QIANKUN__ ? window.commonComponent.VueUeditorWrap : VueUeditorWrap
},
调用主应用中的VueUeditorWrap,确保路径读取到,也能动态使用。
终于清净了,没有报错了。