最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

詳解Vue基于vue-quill-editor富文本編輯器使用心得

 更新時(shí)間:2019年01月03日 09:41:11   作者:張子浩  
這篇文章主要介紹了Vue基于vue-quill-editor富文本編輯器使用心得,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧

vue-quill-editor的guthub地址 ,現(xiàn)在市面上有很多的富文本編輯器,我個(gè)人還是非常推薦Vue自己家的vue-quill-deitor,雖然說(shuō)只支持IE10+,但這種問(wèn)題,帥給別人吧!

那么我們直擊正題,在vue中使用quill呢,我們需要npm進(jìn)行安裝,安裝命令如下:

npm install vue-quill-editor

再安裝依賴項(xiàng)

npm install quill

使用:

在main.js中進(jìn)行引入

import Vue from 'vue'
import VueQuillEditor from 'vue-quill-editor'
import 'quill/dist/quill.core.css'
import 'quill/dist/quill.snow.css'
import 'quill/dist/quill.bubble.css'
 
Vue.use(VueQuillEditor)

下面的css一定還要引用,否則編輯器將會(huì)沒(méi)有css。

在vue頁(yè)面中代碼如下:

<template>
 <div class="edit_container">
  <quill-editor 
   v-model="content" 
   ref="myQuillEditor" 
   :options="editorOption" 
   @blur="onEditorBlur($event)" @focus="onEditorFocus($event)"
   @change="onEditorChange($event)">
  </quill-editor>
  <button v-on:click="saveHtml">保存</button>
 </div> 
</template>

<script>
export default {
 name: 'App',
 data(){
  return {
   content: `<p>hello world</p>`,
   editorOption: {}
  }
 },computed: {
  editor() {
   return this.$refs.myQuillEditor.quill;
  },
 },methods: {
  onEditorReady(editor) { // 準(zhǔn)備編輯器
  },
  onEditorBlur(){}, // 失去焦點(diǎn)事件
  onEditorFocus(){}, // 獲得焦點(diǎn)事件
  onEditorChange(){}, // 內(nèi)容改變事件
  saveHtml:function(event){
   alert(this.content);
  }
 }
}
</script>

<style>
#app {
 font-family: 'Avenir', Helvetica, Arial, sans-serif;
 -webkit-font-smoothing: antialiased;
 -moz-osx-font-smoothing: grayscale;
 text-align: center;
 color: #2c3e50;
 margin-top: 60px;
}
</style>

其中的v-model就是我們自己的html代碼,你可以將這個(gè)html直接放到數(shù)據(jù)庫(kù),這樣也就沒(méi)有什么問(wèn)題了。如果想要禁用編輯器可以通過(guò)以下代碼:

onEditorFocus(val,editor){ // 富文本獲得焦點(diǎn)時(shí)的事件
  console.log(val); // 富文本獲得焦點(diǎn)時(shí)的內(nèi)容
  editor.enable(false); // 在獲取焦點(diǎn)的時(shí)候禁用
 }

主題設(shè)置

在vue項(xiàng)目中,具體引入Quill的文件中,需要使用哪種主題就寫哪個(gè)。默認(rèn)是snow主題的。

data(){
  return {
   content: `<p>hello world</p>`,
   editorOption: {
    theme:'snow'
   }
  }
 }

工具欄設(shè)置

modules:{
   toolbar:[
    ['bold', 'italic', 'underline', 'strike'], //加粗,斜體,下劃線,刪除線
    ['blockquote', 'code-block'],  //引用,代碼塊
 
 
    [{ 'header': 1 }, { 'header': 2 }],  // 標(biāo)題,鍵值對(duì)的形式;1、2表示字體大小
    [{ 'list': 'ordered'}, { 'list': 'bullet' }],  //列表
    [{ 'script': 'sub'}, { 'script': 'super' }], // 上下標(biāo)
    [{ 'indent': '-1'}, { 'indent': '+1' }],  // 縮進(jìn)
    [{ 'direction': 'rtl' }],    // 文本方向
 
 
    [{ 'size': ['small', false, 'large', 'huge'] }], // 字體大小
    [{ 'header': [1, 2, 3, 4, 5, 6, false] }],  //幾級(jí)標(biāo)題
 
 
    [{ 'color': [] }, { 'background': [] }],  // 字體顏色,字體背景顏色
    [{ 'font': [] }],  //字體
    [{ 'align': [] }], //對(duì)齊方式
 
 
    ['clean'], //清除字體樣式
    ['image','video'] //上傳圖片、上傳視頻
 
   ]
   },
   theme:'snow'
  }
  }

圖片推拽上傳

需要安裝  quill-image-drop-module 模塊,那么改一下imageDrop設(shè)置為true,你就可以把你電腦上的圖片網(wǎng)上一坨就可以了。

import { quillEditor } from 'vue-quill-editor'
import * as Quill from 'quill' //引入編輯器
import { ImageDrop } from 'quill-image-drop-module';
Quill.register('modules/imageDrop', ImageDrop);
export default {
 name: 'App',
 data(){ 
  return{
  editorOption:{
   modules:{
   imageDrop:true, 
   },
   theme:'snow'
  }
  }
 }

那上傳文件那你就不用想了,你也許想先把圖片放上去,其實(shí)這個(gè)文件托上去就已經(jīng)是個(gè)base64了,等你在前臺(tái)讀數(shù)的時(shí)候直接decode就好~

圖片調(diào)整大小ImageResize

return{
  editorOption:{
   modules:{
        imageResize: {}
   },
   theme:'snow'
  }
  }

以上就是我對(duì)vue-quill-editor的認(rèn)識(shí), 希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論

博罗县| 洛南县| 肇州县| 宜春市| 来安县| 平舆县| 同江市| 邳州市| 苏尼特右旗| 梨树县| 霍城县| 井陉县| 花垣县| 景德镇市| 亳州市| 德格县| 茂名市| 芜湖县| 临洮县| 巴青县| 洪雅县| 长子县| 达尔| 城口县| 普定县| 巩义市| 卫辉市| 佛学| 房产| 梁河县| 辽源市| 安溪县| 德昌县| 贵德县| 凤凰县| 武平县| 弥勒县| 绍兴县| 东乌珠穆沁旗| 泌阳县| 康保县|