vue富文本编辑器组件vue-quill-edit使用教程
2018-09-21 11:29
1061 查看
之前使用的富文本编辑器是uEditor,kindEditor,感觉不太方便。
近期项目vue单页面,就使用vue-quill-edit这个编辑器组件吧!
一、安装 cnpm install vue-quill-editor
二、引入
在main.js引入并注册:
import VueQuillEditor from 'vue-quill-editor' // require styles 引入样式 import 'quill/dist/quill.core.css' import 'quill/dist/quill.snow.css' import 'quill/dist/quill.bubble.css' Vue.use(VueQuillEditor)
三、封装组件
<template> <div class="quill_box"> <quill-editor v-model="content" ref="myQuillEditor" :options="editorOption" @blur="onEditorBlur($event)" @focus="onEditorFocus($event)" @change="onEditorChange($event)"> </quill-editor> </div> </template> <script> import Bus from "../../assets/utils/eventBus"; export default { data() { return { content:'', editorOption: { placeholder: "请编辑内容", modules: { toolbar: [ ["bold", "italic", "underline", "strike"], ["blockquote", "code-block"], [{ list: "ordered" }, { list: "bullet" }], [{ script: "sub" }, { script: "super" }], [{ indent: "-1" }, { indent: "+1" }], [{ size: ["small", false, "large", "huge"] }], [{ font: [] }], [{ color: [] }, { background: [] }], [{ align: [] }], [ "image"] ] } } }; }, props:[ 'contentDefault' ], watch:{ contentDefault:function(){ this.content = this.contentDefault; } }, mounted:function(){ this.content = this.contentDefault; }, methods: { onEditorBlur() { //失去焦点事件 // console.log('失去焦点'); }, onEditorFocus() { //获得焦点事件 // console.log('获得焦点事件'); }, onEditorChange() { //内容改变事件 // console.log('内容改变事件'); Bus.$emit('getEditorCode',this.content) } } }; </script> <style lang="less"> .quill_box{ .ql-toolbar.ql-snow{border-color:#dcdfe6;} .ql-container{height:200px !important;border-color:#dcdfe6;} .ql-snow .ql-picker-label::before { position: relative; top: -10px; } .ql-snow .ql-color-picker .ql-picker-label svg, .ql-snow .ql-icon-picker .ql-picker-label svg{position: relative;top:-6px;} } </style>
四、引入使用
<my-editor :contentDefault="contentDefault"></my-editor> components:{ myEditor:myEditorComponent },
相关文章推荐
- Vue.js组件使用开发实例教程
- vue中的router-view组件的使用教程
- Vue-Quill-Editor富文本编辑器的使用教程
- vue-cli 组件的导入与使用教程详解
- Vue 组件封装 并使用 NPM 发布的教程
- vue教程3-01 路由、组件、bower包管理器使用
- Vue组件的使用教程详解
- [js高手之路] vue系列教程 - 组件定义与使用上部(7)
- 使用Vue开发动态刷新Echarts组件的教程详解
- vue项目国际化vue-i18n的安装使用教程
- 怎么直接中vue组件的style使用less,不是引入less
- 浅谈vue自定义全局组件并通过全局方法 Vue.use() 使用该组件
- vue组件化挖矿之旅(三):vue-cli 自定义过滤器的使用
- 使用Vue构建Ionic混合APP系列教程(三):服务和Http请求
- Jasperreports+jaspersoft studio学习教程(七)- Table组件的使用
- vue 基础-->进阶 教程(2): 指令、自定义指令、组件
- vue 怎么创建组件及组件使用方法
- vue2使用vue-quill-editor
- VUE 饿了么组件 el-table 的<template scope="scope">使用
- jQuery Mobile中的button按钮组件基础使用教程