103 lines
2.3 KiB
Java
103 lines
2.3 KiB
Java
<!-- UEditor -->
|
|
<template>
|
|
<div>
|
|
<script id="editor" type="text/plain" ></script>
|
|
</div>
|
|
</template>
|
|
|
|
<script>
|
|
|
|
import '@/../public/ueditor/ueditor.config.js'
|
|
import '@/../public/ueditor/ueditor.all.js'
|
|
import '@/../public/ueditor/lang/zh-cn/zh-cn.js'
|
|
import '@/../public/ueditor/lang/en/en.js'
|
|
|
|
export default {
|
|
name: 'UEditor',
|
|
data () {
|
|
return {
|
|
editor: null
|
|
}
|
|
},
|
|
methods: {
|
|
getUEContent: function () {
|
|
// return this.editor.ready(()=>{
|
|
// this.editor.getContent()
|
|
// })
|
|
return this.editor.getContent()
|
|
},
|
|
getContentTxt: function () {
|
|
return this.editor.getContentTxt()
|
|
},
|
|
setContent (content) {
|
|
return this.editor.ready(()=>{
|
|
this.editor.setContent(content,true)
|
|
})
|
|
},
|
|
// 清空内容
|
|
execCommand (content) {
|
|
return this.editor.execCommand('cleardoc')
|
|
},
|
|
getContentLength () {
|
|
return this.editor.getContentLength()
|
|
}
|
|
},
|
|
props: {
|
|
id: {
|
|
type: String
|
|
},
|
|
config: {
|
|
type: Object
|
|
},
|
|
fontfamily: {
|
|
type: String,
|
|
default: ''
|
|
},
|
|
fontsize: {
|
|
type: String,
|
|
default: ''
|
|
},
|
|
bold: {
|
|
type: Boolean,
|
|
default: false
|
|
},
|
|
content:{
|
|
type: String,
|
|
default: ''
|
|
}
|
|
},
|
|
watch: {
|
|
},
|
|
mounted () {
|
|
UEDITOR_CONFIG.UEDITOR_HOME_URL = '../../public/ueditor/'
|
|
// 初始化UE
|
|
this.editor = UE.delEditor('editor')
|
|
this.editor = UE.getEditor('editor', this.config)
|
|
let _this = this
|
|
UE.getEditor('editor').addListener('blur',function(editor){
|
|
_this.$emit('editor-onChange', _this.getUEContent())
|
|
});
|
|
UE.getEditor('editor').ready(function() {
|
|
if (_this.fontfamily !== '') {
|
|
UE.getEditor('editor').execCommand( 'fontfamily',_this.fontfamily)
|
|
}
|
|
if (_this.content !== '') {
|
|
UE.getEditor('editor').setContent(_this.content)
|
|
}
|
|
if (_this.fontsize !== '') {
|
|
UE.getEditor('editor').execCommand( 'fontsize', _this.fontsize )
|
|
}
|
|
if (_this.bold) {
|
|
UE.getEditor('editor').execCommand('bold')
|
|
}
|
|
|
|
});
|
|
},
|
|
beforeDestroy() {
|
|
},
|
|
destoryed () {
|
|
this.editor.destory()
|
|
}
|
|
}
|
|
</script>
|