前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >vue-quill-editor 简单配置demo

vue-quill-editor 简单配置demo

作者头像
李维亮
发布2022-04-07 16:04:15
1.6K0
发布2022-04-07 16:04:15
举报
文章被收录于专栏:李维亮的博客李维亮的博客

项目main.js文件引入

代码语言:javascript
复制
import VueQuillEditor from 'vue-quill-editor'

// require styles
import 'quill/dist/quill.core.css'
import 'quill/dist/quill.snow.css'
import 'quill/dist/quill.bubble.css'

Vue.use(VueQuillEditor, /* { default global options } */)
/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  components: { App,VueQuillEditor }, //组件中注册
  template: '<App/>'
})

新建一个editor-demo.vue文件,下面注释部分是局部引入方法

代码语言:javascript
复制
<template>
  <div>
    <quill-editor v-model="content"
                  ref="myQuillEditor"
                  :options="editorOption"
                  @blur="onEditorBlur($event)">
    </quill-editor>
    <button class="saveBtn" @click="save">保存</button>
    <pre>
      {{storageCont}}
    </pre>
    <div v-html="storageCont"></div>

  </div>
</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 {
    name: "editor-demo",
    // components: {
    //   quillEditor
    // },
    data() {
      return {
        content: '<h2>I am Example</h2>',
        storageCont:'',
        editorOption: {
          // some quill options
          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] }],
              [{ 'font': [] }],
              [{ 'color': [] }, { 'background': [] }],
              [{ 'align': [] }],
              ['clean'],
              ['link', 'image', 'video'],
              ['table']
            ],
          }

        }
      }
    },
    methods: {
      save(){
        this.storageCont = JSON.parse(JSON.stringify(this.content))
      },
      onEditorBlur(quill) {
        console.log('editor blur!', quill)
        console.log(this.content)
      },
    },
    // computed: {
    //   editor() {
    //     return this.$refs.myQuillEditor.quill
    //   }
    // },
    // mounted() {
    //   console.log('this is current quill instance object', this.editor)
    // }
  }
</script>

<style scoped>
.saveBtn{
  float: right;
  margin-top: 15px;
  border: 1px solid #409EFF;
  padding: 8px 20px;
  color: #fff;
  background-color: #409EFF;
}
  pre{
    margin-top: 90px;
    display: block;
    padding: 10px;
    color: #839496;
    font-size: 14px;
    border: 1px solid #ccc;
    white-space: pre-wrap;
    background: #002b36;
    font-family: Menlo,Monaco,Consolas,"Lucida Console","Courier New",monospace;
    font-size: 1em;
  }
</style>
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2022-04-01,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档