富文本编辑器vue-quill-editor的高级用法(一)之更改编辑器的样式

66 阅读1分钟

前言
基础用法请看上一篇

<template>
  <!-- Two-way Data-Binding -->
  <quill-editor class='editor' ref="myQuillEditor" v-model="content" :options="editorOption" @blur="onEditorBlur($event)"
    @focus="onEditorFocus($event)" @ready="onEditorReady($event)" @change="onEditorChange($event)" />
</template>
 

<script>
import 'quill/dist/quill.core.css'
import 'quill/dist/quill.snow.css'
import 'quill/dist/quill.bubble.css'
import { quillEditor } from 'vue-quill-editor'

export default {
  components: {
    quillEditor
  },
  data() {
    return {
      content: ``, // 富文本编辑器默认内容
      editorOption: {}
    }
  },
  methods: {
    //失去焦点事件
    onEditorBlur(quill) {
      console.log('editor blur!', quill)
    },
    //获得焦点事件
    onEditorFocus(quill) {
      console.log('editor focus!', quill)
    },
    // 准备富文本编辑器
    onEditorReady(quill) {
      console.log('editor ready!', quill)
    },
    //内容改变事件
    onEditorChange({ quill, html, text }) {
      console.log('editor change!', quill, html, text)
      this.content = html
    }
  }
}

</script>

<style scoped lang="scss">
.editor {//更改富文本编辑器的宽度和高度
  line-height: normal !important;
  height: 500px;
  width:60%;
}
::v-deep .ql-toolbar.ql-snow{//更改富文本编辑器工具栏的背景颜色和边框
  background-color:#FAFAFA;
  border: 1px solid #eee!important;
}
::v-deep .ql-container.ql-snow{//更改富文本编辑器编辑区域的边框
  border:1px solid #eee!important;
}
</style>