vue2中使用vue-quill-editor实现编辑器

1 参考文档

开发文档

https://github.com/surmon-china/vue-quill-editor

例子

vue-quill-editor | Homepage | Surmon's projects

中文开发文档

前言 · Quill官方中文文档 · 看云

版本号(注意:不适用于vue3)

 "quill": "^1.3.7",
 "quill-image-drop-module": "^1.0.3",
 "quill-image-resize-module": "^3.0.0",
 "vue": "^2.6.11",
 "vue-quill-editor": "^3.0.6"

2 截图

3 源代码

3.1 vue.config.js

// 解决import模块quill-image-resize-module错误
const webpack = require('webpack')
module.exports = {
    chainWebpack: config => {
        config.plugin('provide').use(webpack.ProvidePlugin, [{
            'window.Quill': 'quill/dist/quill.js',
            'Quill': 'quill/dist/quill.js'
        }]);
    }
}

3.2 vue源代码

<template>
  <div>
    <quill-editor
      ref="myTextEditor"
      v-bind:options="editorOption"
      v-model="content">
    </quill-editor>
  </div>
</template>
 
<script>
​
// 设置基本的编辑框
import { quillEditor } from 'vue-quill-editor'
import 'quill/dist/quill.core.css'
import 'quill/dist/quill.snow.css'
import 'quill/dist/quill.bubble.css'
​
import { Quill } from 'vue-quill-editor'
// 设置调整图片大小
import ImageResize from "quill-image-resize-module";
Quill.register("modules/imageResize", ImageResize);
// 设置拖拽
import { ImageDrop } from "quill-image-drop-module";
Quill.register("modules/imageDrop", ImageDrop);
​
export default {
  components: {
    quillEditor
  },
  data () {
    return {
      content: "Hello quill",
      editorOption: null
    }
  },
  created: function(){
    // 工具栏配置
    const toolbarOption = [
      ["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"]
    ];
​
    this.editorOption = {
        theme: "snow",
        placeholder: "请输入正文",
        modules: {
          // 设置拖拽
          imageDrop: true,
​
          //设置图片大小, 也可以使用"imageResize:true",官网上采用的是下面的配置方式
          imageResize: {
            displayStyles: {
              backgroundColor: 'black',
              border: 'none',
              color: 'white'
            },
            modules: [ 'Resize', 'DisplaySize', 'Toolbar' ]
          },
​
          toolbar: {
            container: toolbarOption
          }
        }
      }
  }
}
</script>
 
<style>
</style>

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值