value: '',
config: {}
},
mounted () {
this.editor = window.UE.getEditor('editor', this.config);
this.editor.addListener('ready', () => {
this.editor.setContent(this.value)
})
},
methods: {
getUEContent () {
return this.editor.getContent()
}
},
destroyed () {
this.editor.destroy()
}
}
</script>
组件暴露了两个接口:
value是编辑器的文字
config是编辑器的配置参数在其他页面中使用该组件
简单地创建一个需要UEditor的页面,再该页面中使用刚才封装好的UE.vue组件:
<template>
<div>
<Uediter :value="ueditor.value" :config="ueditor.config" ref="ue"></Uediter>
<button @click="returnContent">显示编辑器内容</el-button>
<div>{{dat.content}}</div>
</div>
</template>
<script>
import Uediter from '@/components/UE.vue'; export default {
data () {
return {
dat: {
content: ''
},
ueditor: {
value: '编辑器默认文字',
config: {
initialFrameWidth: 800,
initialFrameHeight: 320
}
}
}
},
methods: {
returnContent () {
this.dat.content = this.$refs.ue.getUEContent()
}
},
components: {
Uediter
},
}
</script>
效果如下:

What’s more: 服务端需要做的配置
配置完上述内容后,控制台可能会出现”后台配置项返回格式出错,上传功能将不能正常使用!”的报错,
我们在编辑器中上传图片或者视频,也会出现响应的报错,这是因为没有配置服务器的请求接口,在ueditor.config.js中,对serverUrl进行配置:
// 服务器统一请求接口路径
, serverUrl: 'http://172.16.254.49:83/File/UEditor' //地址管你们后端要去










