欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

 更新時間:2018年09月21日 14:32:47   作者:senmage  
這篇文章主要為大家詳細介紹了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)文章

  • 詳解VS Code使用之Vue工程配置format代碼格式化

    詳解VS Code使用之Vue工程配置format代碼格式化

    這篇文章主要介紹了詳解VS Code使用之Vue工程配置format代碼格式化,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-03-03
  • VUE使用axios調(diào)用后臺API接口的方法

    VUE使用axios調(diào)用后臺API接口的方法

    這篇文章主要介紹了VUE使用axios調(diào)用后臺API接口的方法,文中講解非常細致,代碼幫助大家更好的理解和學(xué)習(xí),感興趣的朋友可以了解下
    2020-08-08
  • vue項目中onscroll的坑及解決

    vue項目中onscroll的坑及解決

    這篇文章主要介紹了vue項目中onscroll的坑及解決方案,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2024-03-03
  • 詳解vue3.0 的 Composition API 的一種使用方法

    詳解vue3.0 的 Composition API 的一種使用方法

    這篇文章主要介紹了vue3.0 的 Composition API 的一種使用方法,本文給大家介紹的非常詳細,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2020-10-10
  • vue axios 表單提交上傳圖片的實例

    vue axios 表單提交上傳圖片的實例

    下面小編就為大家分享一篇vue axios 表單提交上傳圖片的實例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-03-03
  • Vue實現(xiàn)錄制屏幕并本地保存功能

    Vue實現(xiàn)錄制屏幕并本地保存功能

    這篇文章主要介紹了Vue實現(xiàn)錄制屏幕功能并本地保存,這里用的是用的是HBuilder?X開發(fā),結(jié)合示例代碼給大家介紹的非常詳細,需要的朋友可以參考下
    2022-04-04
  • Vue2路由動畫效果的實現(xiàn)代碼

    Vue2路由動畫效果的實現(xiàn)代碼

    本篇文章主要介紹了Vue2路由動畫效果的實現(xiàn)代碼,可以根據(jù)不同的路徑去改變動畫的效果,有興趣的可以了解一下
    2017-07-07
  • vue中的config目錄下index.js解讀

    vue中的config目錄下index.js解讀

    這篇文章主要介紹了vue中的config目錄下index.js解讀,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2023-03-03
  • 一個因@click.stop引發(fā)的bug的解決

    一個因@click.stop引發(fā)的bug的解決

    這篇文章主要介紹了一個因@click.stop引發(fā)的bug的解決,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2019-01-01
  • Vue對話框組件使用方法詳解

    Vue對話框組件使用方法詳解

    這篇文章主要為大家詳細介紹了Vue對話框組件的使用方法,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-03-03

最新評論