引入项目的是编译后的1.5.0版本的UEditor,我另一篇文章写的如何编译1.5.0版本的UEditor
编译后,把dist
文件里面文件放到项目的public/plugins/ueditor
相关自定义配置看官方文档就行了,为了快速把项目搭建好,我就改了ueditor.config.js
的根路径
注意路径最前面也要加上/
之后在component
文件夹下创建一个UEditor.vue
文件,在里面初始化UEditor。
<template>
<div id="ueditor"></div>
</template>
<script>
import '../../../public/plugins/UEditor/ueditor.config'
import '../../../public/plugins/UEditor/ueditor.all'
import '../../../public/plugins/UEditor/lang/zh-cn/zh-cn'
import '../../../public/plugins/UEditor/themes/default/css/ueditor.css'
export default {
name: "UEditor",
data() {
return {
UEditor: null
}
},
mounted() {
this.initUEditor()
},
beforeDestroy() {
if (this.UEditor && this.UEditor.destroy) this.UEditor.destroy()
},
methods: {
initUEditor() {
let config = {
fullscreen: true
}
// eslint-disable-next-line no-undef
this.UEditor = UE.getEditor('ueditor', config)
this.UEditor.addEventListener('ready', () => {
console.log('UEditor is Ready')
})
}
}
}
</script>
<style>
</style>
后面要对代码进行优化,比如config
设置为可传参数、id也是(为了兼容多编辑器共存的问题)
或者通过setContent
和事件总线bus,来实现编辑器里面值得绑定。