java中使用ue文本编辑器_vue2.0项目中使用Ueditor富文本编辑器示例代码

最近在vue项目中需要使用富文本编辑器,于是将Ueditor集成进来,作为公共组件。

1.放入静态资源并配置

首先把官网下载的Ueditor资源,放入静态资源src/static中。

4ce3b530aa78c124f904db097e1d913c.png

修改ueditor.config.js中的window.UEDITOR_HOME_URL配置,如下图:

5c93204c736168a687fa255d67625e0d.png

2.引入

在main.js中引入

import '../static/UE/ueditor.config.js'

import '../static/UE/ueditor.all.min.js'

import '../static/UE/lang/zh-cn/zh-cn.js'

import '../static/UE/ueditor.parse.min.js'

3.开发公共组件

开发公共组件,可设置填充内容defaultMsg,配置信息config(宽度和高度等),并提供获取内容的方法。

export default {

name: 'UE',

data () {

return {

editor: null

}

},

props: {

defaultMsg: {

type: String

},

config: {

type: Object

}

},

mounted() {

const _this = this;

this.editor = UE.getEditor('editor', this.config); // 初始化UE

this.editor.addListener("ready", function () {

_this.editor.setContent(_this.defaultMsg); // 确保UE加载完成后,放入内容。

});

},

methods: {

getUEContent() { // 获取内容方法

return this.editor.getContent()

}

},

destroyed() {

this.editor.destroy();

}

}

4.使用

当我们需要使用富文本编辑器时,直接调用公共组件即可

UE编辑器示例
需要使用编辑器时,调用UE公共组件即可。可设置填充内容defaultMsg,配置信息config(宽度和高度等),可调用组件中获取内容的方法。

获取内容

.info{

border-radius: 10px;

line-height: 20px;

padding: 10px;

margin: 10px;

background-color: #ffffff;

}

import UE from '../../components/ue/ue.vue';

export default {

components: {UE},

data() {

return {

defaultMsg: '这里是UE测试',

config: {

initialFrameWidth: null,

initialFrameHeight: 350

}

}

},

methods: {

getUEContent() {

let content = this.$refs.ue.getUEContent();

this.$notify({

title: '获取成功,可在控制台查看!',

message: content,

type: 'success'

});

console.log(content)

}

}

};

效果如下:

136e34fc66e1bf043056de2ce52ffb89.png

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值