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

Vue-Quill-Editor富文本編輯器的使用教程

 更新時間:2018年09月21日 14:32:47   作者:senmage  
這篇文章主要為大家詳細(xì)介紹了Vue-Quill-Editor富文本編輯器的使用教程,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文為大家分享了Vue Quill Editor富文本編輯器的具體使用方法,供大家參考,具體內(nèi)容如下

先看效果圖:

    

 1、下載Vue-Quill-Editor 

npm install vue-quill-editor --save

2、下載quill(Vue-Quill-Editor需要依賴) 

npm install quill --save 

3、代碼 

<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>
  </div>
</template>
<script>
import { quillEditor } from "vue-quill-editor"; //調(diào)用編輯器
import 'quill/dist/quill.core.css';
import 'quill/dist/quill.snow.css';
import 'quill/dist/quill.bubble.css';
export default {
  components: {
    quillEditor
  },
  data() {
    return {
      content: `<p></p><p><br></p><ol><li><strong><em>Or drag/paste an image here.</em></strong></li><li><strong><em>rerew</em></strong></li><li><strong><em>rtrete</em></strong></li><li><strong><em>tytrytr</em></strong></li><li><strong><em>uytu</em></strong></li></ol>`,
      editorOption: {}
    }
  },
  methods: {
    onEditorReady(editor) { // 準(zhǔn)備編輯器
 
    },
    onEditorBlur(){}, // 失去焦點事件
    onEditorFocus(){}, // 獲得焦點事件
    onEditorChange(){}, // 內(nèi)容改變事件
  },
  computed: {
    editor() {
      return this.$refs.myQuillEditor.quill;
    },
  }
}
</script>

OK,搞定,簡潔的富文本編輯器就展現(xiàn)在你眼前了,另外附上API。Vue-Quill-Editor

4、存儲及將數(shù)據(jù)庫中的數(shù)據(jù)反顯為HTML字符串

后臺接收到數(shù)據(jù)后會將字符中的標(biāo)簽進行轉(zhuǎn)碼,所以我們要先進行一個解碼的操作讓他變成標(biāo)簽形式的字符串:
例如后臺接收的數(shù)據(jù)如下:"&lt;h1&gt;title&lt;"  ,對應(yīng)解碼后就是`<h1>title</h1>`。

//把實體格式字符串轉(zhuǎn)義成HTML格式的字符串
escapeStringHTML(str) {
  str = str.replace(/&lt;/g,'<');
  str = str.replace(/&gt;/g,'>');
  return str;
}

然后將返回值賦值給對應(yīng)的參數(shù): 

<div v-html="str" class="ql-editor">
  {{str}}
</div>

上面的str就是轉(zhuǎn)碼函數(shù)返回的值,我們要先在data中定義,所以我現(xiàn)在將新增跟展示放在一起,代碼如下:

<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>
    <!-- 從數(shù)據(jù)庫讀取展示 -->
    <div v-html="str" class="ql-editor">
      {{str}}
    </div>
  </div>
</template>
<script>
import { quillEditor } from "vue-quill-editor"; //調(diào)用編輯器
import 'quill/dist/quill.core.css';
import 'quill/dist/quill.snow.css';
import 'quill/dist/quill.bubble.css';
export default {
  components: {
    quillEditor
  },
  data() {
    return {
      content: `<p></p><p><br></p><ol><li><strong><em>Or drag/paste an image here.</em></strong></li><li><strong><em>rerew</em></strong></li><li><strong><em>rtrete</em></strong></li><li><strong><em>tytrytr</em></strong></li><li><strong><em>uytu</em></strong></li></ol>`,
      str: '',
      editorOption: {}
    }
  },
  methods: {
    onEditorReady(editor) { // 準(zhǔn)備編輯器
 
    },
    onEditorBlur(){}, // 失去焦點事件
    onEditorFocus(){}, // 獲得焦點事件
    onEditorChange(){}, // 內(nèi)容改變事件
    // 轉(zhuǎn)碼
    escapeStringHTML(str) {
      str = str.replace(/&lt;/g,'<');
      str = str.replace(/&gt;/g,'>');
      return str;
    }
  },
  computed: {
    editor() {
      return this.$refs.myQuillEditor.quill;
    },
  },
  mounted() {
    let content = ''; // 請求后臺返回的內(nèi)容字符串
    this.str = this.escapeStringHTML(content);
  }
}
</script>

 以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Vue使用swiper問題(5.2.0版本,避免踩坑)

    Vue使用swiper問題(5.2.0版本,避免踩坑)

    這篇文章主要介紹了Vue使用swiper問題(5.2.0版本,避免踩坑),具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2023-04-04
  • Vue數(shù)據(jù)綁定實例寫法

    Vue數(shù)據(jù)綁定實例寫法

    在本篇文章里小編給大家整理的是關(guān)于Vue數(shù)據(jù)綁定實例寫法以及相關(guān)知識點,需要的朋友們學(xué)習(xí)下。
    2019-08-08
  • vue項目初始化到登錄login頁面的示例

    vue項目初始化到登錄login頁面的示例

    今天小編就為大家分享一篇vue項目初始化到登錄login頁面的示例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2019-10-10
  • vue如何動態(tài)修改meta的title

    vue如何動態(tài)修改meta的title

    這篇文章主要介紹了vue如何動態(tài)修改meta的title,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-06-06
  • vue bus全局事件中心簡單Demo詳解

    vue bus全局事件中心簡單Demo詳解

    ue-bus 提供了一個全局事件中心,并將其注入每一個組件,你可以像使用內(nèi)置事件流一樣方便的使用全局事件。這篇文章給大家介紹了vue bus全局事件中心簡單Demo,需要的朋友參考下吧
    2018-02-02
  • Vue獲取DOM的幾種方法總結(jié)

    Vue獲取DOM的幾種方法總結(jié)

    這篇文章主要介紹了Vue獲取DOM的幾種方法總結(jié),具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-10-10
  • vue組件component的注冊與使用詳解

    vue組件component的注冊與使用詳解

    組件是Vue是一個可以重復(fù)使用的Vue實例, 它擁有獨一無二的組件名稱,它可以擴展HTML元素,以組件名稱的方式作為自定義的HTML標(biāo)簽,這篇文章主要介紹了vue組件component的注冊與使用,需要的朋友可以參考下
    2022-08-08
  • vue中圖片加載不出來的問題及解決

    vue中圖片加載不出來的問題及解決

    這篇文章主要介紹了vue中圖片加載不出來的問題及解決,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-03-03
  • vue-admin如何實現(xiàn)動態(tài)路由

    vue-admin如何實現(xiàn)動態(tài)路由

    這篇文章主要介紹了vue-admin如何實現(xiàn)動態(tài)路由問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2024-07-07
  • Vue關(guān)于element穿梭框進行的修改成table表格穿梭框方式

    Vue關(guān)于element穿梭框進行的修改成table表格穿梭框方式

    這篇文章主要介紹了Vue關(guān)于element穿梭框進行的修改成table表格穿梭框方式,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2024-04-04

最新評論

中卫市| 武功县| 那坡县| 丘北县| 肥乡县| 赞皇县| 郸城县| 长春市| 师宗县| 鹤岗市| 新蔡县| 安徽省| 定日县| 高碑店市| 绿春县| 曲靖市| 梅河口市| 邓州市| 深圳市| 桑日县| 旬邑县| 九江县| 威海市| 临安市| 奉化市| 剑河县| 德格县| 封丘县| 常山县| 正镶白旗| 根河市| 温宿县| 永和县| 尚义县| 蓬溪县| 宁陵县| 武强县| 罗定市| 芜湖市| 江都市| 吉隆县|