欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

vue如何安装使用Quill富文本编辑器

程序员文章站 2022-07-20 18:09:07
本文为大家记录了vue中安装使用quill富文本编辑器的具体方法,供大家参考,具体内容如下 1、安装依赖 npm install vue-quill-edito...

本文为大家记录了vue中安装使用quill富文本编辑器的具体方法,供大家参考,具体内容如下

1、安装依赖

npm install vue-quill-editor --save

注:我在已有的vue项目中(含有已安装的依赖,即node_modules文件夹)直接进行安装并不成功,报错,没有截图,但是我没记错的话是显示"项目名\node_modules\cliui\node_modules\wordwrap"这个没有。所以我把项目下的node_modules文件删除,然后直接安装quill依赖(执行npm install vue-quill-editor --save)。然后npm run dev 运行项目,不影响之前vue项目的使用和运行,quill的富文本编辑器也可以用了。

2、使用

(1)在“项目名\src\main.js”引入

import vue from 'vue'
import vuequilleditor from 'vue-quill-editor'
//一定要引入这三个css,不然文本编辑器会出现不规则黑白几何图形
//这三个css可以在main.js中引入,也可以在具体使用的.vue文件中引入
import 'quill/dist/quill.core.css'
import 'quill/dist/quill.snow.css'
import 'quill/dist/quill.bubble.css'
 
vue.use(vuequilleditor)

(2)在具体vue文件中引用

<template>
 <el-row>
   <quill-editor v-model="content"
    :options="editoroption" 
    @blur="oneditorblur($event)" 
    @focus="oneditorfocus($event)"
    @change="oneditorchange($event)">
   </quill-editor>
 </el-row>
</template>
<script>
import { quilleditor } from 'vue-quill-editor'
 
export default {
  data:function(){
   return{
    content:'',
    editoroption:{}
   }
  },
  methods:{
   oneditorblur(editor){//失去焦点事件 
  },
   oneditorfocus(editor){//获得焦点事件
   },
   oneditorchange({editor,html,text}){//编辑器文本发生变化
    //this.content可以实时获取到当前编辑器内的文本内容
    console.log(this.content);
   }
  }
}
 
</script>

v-model 可以不使用,并不是quill编辑器自带的,是我项目中使用自己加的。

这样引入后可以得到一个这样的编辑器。

vue如何安装使用Quill富文本编辑器

如果需要改变文本域部分的高度,如下:

<style>
 .quill-editor {
  height: 350px;
 }
</style>

quill的自定义工具栏、字体等,请点击:vue中quill富文本编辑器的使用

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。