vue项目中添加富文本编辑器

推荐使用vue-quill-editor 富文本编辑器
官网:https://quilljs.com/

接下来进行操作

1. 首先 在项目中打开终端 输入npm install vue-quill-editor 进行安装

2. 分别引入富文本编辑器及其css样式
   import { quillEditor } from 'vue-quill-editor'
   import 'quill/dist/quill.core.css'
   import 'quill/dist/quill.snow.css'
   import 'quill/dist/quill.bubble.css'

3.在项目中挂载 
   components: {
      quillEditor
   },

4.配置工具栏(也可使用默认工具栏工具)
 modules: {
          // 配置工具栏
          toolbar: [
            ['bold', 'italic', 'underline', 'strike'],
            ['blockquote', 'code-block'],
            [{ header: 1 }, { header: 2 }],
            [{ list: 'ordered' }, { list: 'bullet' }],
            [{ indent: '-1' }, { indent: '+1' }],
            ['image']
          ]
        }

5.使用
/**
 * 删除图片
 * @param {*} article.content  为在data中增添的数据项 用于存储用户在富文本书写的内容
 * @param {*} editorOption 为上面定义的富文本编辑器配置栏
 */
<quill-editor v-model="article.content" :options="editorOption"></quill-editor>

最后效果图

猜你喜欢

转载自blog.csdn.net/weixin_43452467/article/details/110392173