Vue+Element使用富文本编辑器的示例代码

前端之家收集整理的这篇文章主要介绍了Vue+Element使用富文本编辑器的示例代码前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

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

安装编辑器组件

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

编写组件

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

@H_404_30@
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
}
}

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

猜你在找的Vue相关文章