vue2使用vue-quill-editor

一、npm install vue-quill-editor
        npm install quill
二、index.js引入
        import VueQuillEditor from 'vue-quill-editor'
        Vue.use(VueQuillEditor)
三、components文件夹新建xx.vue
        写法<template>
  <!-- Or manually control the data synchronization(或手动控制数据流) -->
  <div class="editor">
    <quill-editor v-model="content"
                  ref="myQuillEditor"
                  :options="editorOption"
                  @blur="onEditorBlur($event)"
                  @focus="onEditorFocus($event)"
                  @ready="onEditorReady($event)">
    </quill-editor>
    <button @click="getContent()">获取内容</button>
  </div>
</template>
<script>
  import Quill from 'quill'
  import { ImageImport } from '../../static/quill/ImageImport.js'
  import { ImageResize } from '../../static/quill/ImageResize.js'
  Quill.register('modules/imageImport', ImageImport)
  Quill.register('modules/imageResize', ImageResize)
  // You can also register quill modules in the component
  export default {
    data () {
      return {
        content: '<h2>I am Example</h2>',
        editorOption: {
          modules: {
            history: {
              delay: 1000,
              maxStack: 50,
              userOnly: false
            },
            imageImport: true,
            imageResize: {
              displaySize: true
            }
          }
        }
      }
    },
    // if you need to manually control the data synchronization, parent component needs to explicitly emit an event instead of relying on implicit binding
    // 如果需要手动控制数据同步,父组件需要显式地处理changed事件
    methods: {
      onEditorBlur (editor) {
        console.log('editor blur!', editor)
      },
      onEditorFocus (editor) {
        console.log('editor focus!', editor)
      },
      onEditorReady (editor) {
        console.log('editor ready!', editor)
      },
      onEditorChange ({ editor, html, text }) {
        console.log('editor change!', editor, html, text)
        this.content = html
      },
      getContent () {
        alert(this.content)
      }
    },
    mounted () {
      // you can use current editor object to do something(quill methods)
      console.log('this is current quill instance object', this.editor)
    }
  }
</script>
其中imageImport和imageResize 需要从github(vue-quill-editor)中的modules 中下载下来
效果

转载于:https://my.oschina.net/u/2439541/blog/1511213

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值