vue html 在线编辑,Vue+Element使用富文本编辑器的示例代码

富文本编辑器在任何项目中都会用到,在Element中我们推荐vue-quill-editor组件,现在我就把它提供给大家,希望对大家有用。具体截图如下:

1c477061e63a2ab37e90e9d1d608ce41.png

安装编辑器组件

具体方法:npm install vue-quill-editor --save

编写组件

首先我们在components文件夹里创建ue.vue组件,效果图如下:

068c3d69d3734d3d84ddc77033066549.png

组件

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();

}

}

在页面中使用

下面是使用代码

首页

关于我们

添加关于我们

ref="myQuillEditor"

class="editer"

:options="editorOption" @ready="onEditorReady($event)">

确认提交

import { quillEditor } from 'vue-quill-editor' //调用编辑器

export default {

data() {

return {

infoForm: {

a_title: '',

a_source: '',

a_content:'',

editorOption: {}

},

//表单验证

rules: {

a_title: [

{required: true, message: '请输入标题', trigger: 'blur'}

],

a_content: [

{required: true, message: '请输入详细内容', trigger: 'blur'}

]

},

}

},

computed: {

editor() {

return this.$refs.myQuillEditor.quill

}

},

mounted() {

//初始化

},

methods: {

onEditorReady(editor) {

},

onSubmit() {

//提交

//this.$refs.infoForm.validate,这是表单验证

this.$refs.infoForm.validate((valid) => {

if(valid) {

this.$post('m/add/about/us',this.infoForm).then(res => {

if(res.errCode == 200) {

this.$message({

message: res.errMsg,

type: 'success'

});

this.$router.push('/aboutus/aboutlist');

} else {

this.$message({

message: res.errMsg,

type:'error'

});

}

});

}

});

}

},

components: {

//使用编辑器

quillEditor

}

}

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值