How to fix wangEditor ‘error in mounted hook’
1 min readDec 16, 2021
Since I upgrade the version of wangEditor from 3.1.1 to 4.7.10, my application cannot load the editor with the ‘error in mounted hook’. The details are as shown in the screenshot.
Obviously, the error caused by the compatible of different versions. To fix this error, we need to add this line of code to make it compatible with old versions:
editor.customConfig = editor.customConfig ? editor.customConfig : editor.config
The snippet of code:
mounted() {
const _this = this
const editor = new E(this.$refs.editor)
// 选择语言
editor.config.lang = 'en'
// 引入 i18next 插件
editor.i18next = window.i18next
editor.customConfig = editor.customConfig ? editor.customConfig : editor.config
// 自定义菜单配置
editor.customConfig.zIndex = 10
// 文件上传
editor.customConfig.customUploadImg = function(files, insert) {
// files 是 input 中选中的文件列表
// insert 是获取图片 url 后,插入到编辑器的方法
files.forEach(image => {
files.forEach(image => {
upload(_this.imagesUploadApi, image).then(data => {
insert(data.data.url)
})
})
})
}
editor.customConfig.onchange = (html) => {
this.form.content = html
}
editor.create()
}
The error is fixed.