安装:
npm install vue-quill-editor --save

安装Vue-Quill-Editor需要依赖:

npm install quill --save

在入口文件main.js 中引入

import QuillEditor from 'vue-quill-editor'
import 'quill/dist/quill.core.css'
import 'quill/dist/quill.bubble.css'
import 'quill/dist/quill.snow.css'
Vue.use(QuillEditor)

在需要的组件中使用  代码如下:

<template>
<div class="content edit_container">
<quill-editor
v-model="content"
ref="myQuillEditor"
:options="editorOption"
@blur="onEditorBlur($event)" @focus="onEditorFocus($event)"
@change="onEditorChange($event)">
</quill-editor>
<button v-on:click="saveHtml">保存</button>
</div>
</template> <script>
export default {
data () {
return {
content: `<p>hello world</p>`,
editorOption: {
theme: 'snow'
},
modules: {
toolbar: [
// ['bold', 'italic', 'underline', 'strike'],
// ['blockquote', 'code-block'],
// [{ 'header': 1 }, { 'header': 2 }],
// [{ 'list': 'ordered'}, { 'list': 'bullet' }],
// [{ 'script': 'sub'}, { 'script': 'super' }],
// [{ 'indent': '-1'}, { 'indent': '+1' }],
// [{ 'direction': 'rtl' }],
// [{ 'size': ['small', false, 'large', 'huge'] }],
// [{ 'header': [1, 2, 3, 4, 5, 6, false] }],
// [{ 'color': [] }, { 'background': [] }],
// [{ 'font': [] }],
// [{ 'align': [] }],
// ['clean'],
// ['image','video']
]
}
}
},
computed: {
editor () {
return this.$refs.myQuillEditor.quill
}
},
methods: {
onEditorReady (editor) { // 准备编辑器
},
onEditorBlur () {}, // 失去焦点事件
onEditorFocus () {}, // 获得焦点事件
onEditorChange () {}, // 内容改变事件
saveHtml (event) {
alert(this.content)
}
}
}
</script> <style>
#app {
font-family: 'Avenir', Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
margin-top: 60px;
}
</style>

这样就完成一个简单的富文本编辑器

最新文章

  1. HTML渲染过程详解
  2. spi子系统之驱动SSD1306 OLED
  3. LINQ系列:Linq to Object元素操作符
  4. C#/.NET 基础学习
  5. 10个经典的C语言面试基础算法及代码
  6. MVC学习笔记---MVC生命周期及管道
  7. WCF与WebService之间的异同
  8. diamond专题(三)—— diamond架构
  9. html5 OPOA
  10. JS使用合并数组
  11. jQuery学习笔记之Ajax用法详解
  12. 关于Data URLs svg图片显示出错和浏览器URL hash #
  13. [Deep Learning] 正则化
  14. 2018-2019-2 网络对抗技术 20165228 Exp5 MSF基础应用
  15. 安装webpack-dev-server始终不成功
  16. IDEA 创建和使用tomcat
  17. java多线程快速入门(六)
  18. Solr之functionQuery(函数查询)
  19. ASP.NET MVC 通过ActionFilterAttribute来实现防止重复提交
  20. [BZOJ1492][NOI2007]cash-[cdq分治]

热门文章

  1. Linux监控工具nmon
  2. Unable to guess the mime type as no guessers are available (Did you enable the php_fileinfo extension?)
  3. IntelliJ IDEA常规配置教程
  4. json_encode中文不转义问题
  5. root xshell登陆Ubuntu
  6. UI组件的学习
  7. 【C语言】多维数组
  8. MAKEFILE_LIST/CURDIR/MAKECMDGOALS/MAKEOVERRIDES/MAKEFLAGS
  9. grep Or And 操作
  10. SAIF anno