SpringBoot+Vue使用ueditor
前言
最近公司突然要给项目换个编辑器, 说是要换成百度的ueditor, 让我研究一下, 咱也不会只能硬着头皮来研究一下; 一通百度下来感觉更
懵了, 这ueditor16年百度就停止更新了, 不知道为啥还要用这玩意; 不过经过我2天多的摸索(遇到了不少的坑)终于成功了…废话不多说, 看
完你不会来砍我(说着玩的)
一. 下载准备
Ueditor文档地址: http://fex.baidu.com/ueditor/
GitHub地址: https://github.com/fex-team/ueditor
这里还是要说一下, 可能有些人会没注意到, dev表示的时开发环境, 我们不要下载这个, 里面没有jsp文件夹
这边咱们下载v1.4.3.3的版本, 解压之后将需要的文件拷贝到前端static文件目录下
这里我们发现官网下载UEditor文件没有ueditor.all.js、ueditor.all.min.js文件, 这边可以参考这篇博客点击, 需要注意如果安装失败需要使
用管理员的权限; 下载成功后就能得到我们需要的js文件了;
二. 前端Vue
2.1 创建vue组件
<template>
<div class="editor-box">
<script id="editor" type="text/plain"></script>
</div>
</template>
<script>
import '../../../static/ueditor/ueditor.config.js'
import '../../../static/ueditor/ueditor.all.min.js'
import '../../../static/ueditor/lang/zh-cn/zh-cn.js'
import '../../../static/ueditor/ueditor.parse.min.js'
export default {
name: 'UE',
data() {
return {
editor: null
}
},
props: {
msg: {
type: String
},
config: {
type: Object,
},
id: {
type: String
}
},
mounted() {
const _this = this;
this.editor = UE.getEditor('editor', this.config); // 初始化UE
this.editor.addListener("ready", function () {
_this.editor.setContent(_this.msg); // 确保UE加载完成后,放入内容。
});
},
methods: {
getUEContent() { // 获取内容方法
return this.editor.getContent();
}
},
destroyed() {
this.editor.destroy();
}
}
</script>
注意: 这边需要注意的是导入的路径不能错误
2.2 使用组件
<template>
<UE :msg=msg :config=config ref="UE" level="normal"></UE>
</template>
<script>
import UE from '@/components/Ueditor'
export default {
name: "ue",
components: {
UE
},
data() {
return {
msg: '',
config: {}
}
},
methods: {
//获取富文本值
getUEMsg() {
this.form.projectContent = this.$refs.UE.getUEContent();
}
}
}
2.3 修改config.js
此处可修改编辑器初始大小
至此, 如果不出问题的话, 前端界面是可以显示编辑器的
但是我们打开控制台, 不出意料之外的话应该会报错; 因为我们后端接口还没有配置
三. 后端配置
3.1 导入核心依赖
<dependency>
<groupId>com