Vue-Quill-Editor富文本編輯器的使用教程
本文為大家分享了Vue Quill Editor富文本編輯器的具體使用方法,供大家參考,具體內(nèi)容如下
先看效果圖:
1、下載Vue-Quill-Editor
npm install vue-quill-editor --save
2、下載quill(Vue-Quill-Editor需要依賴(lài))
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(){}, // 失去焦點(diǎn)事件 onEditorFocus(){}, // 獲得焦點(diǎn)事件 onEditorChange(){}, // 內(nèi)容改變事件 }, computed: { editor() { return this.$refs.myQuillEditor.quill; }, } } </script>
OK,搞定,簡(jiǎn)潔的富文本編輯器就展現(xiàn)在你眼前了,另外附上API。Vue-Quill-Editor
4、存儲(chǔ)及將數(shù)據(jù)庫(kù)中的數(shù)據(jù)反顯為HTML字符串
后臺(tái)接收到數(shù)據(jù)后會(huì)將字符中的標(biāo)簽進(jìn)行轉(zhuǎn)碼,所以我們要先進(jìn)行一個(gè)解碼的操作讓他變成標(biāo)簽形式的字符串:
例如后臺(tái)接收的數(shù)據(jù)如下:"<h1>title<" ,對(duì)應(yīng)解碼后就是`<h1>title</h1>`。
//把實(shí)體格式字符串轉(zhuǎn)義成HTML格式的字符串 escapeStringHTML(str) { str = str.replace(/</g,'<'); str = str.replace(/>/g,'>'); return str; }
然后將返回值賦值給對(duì)應(yīng)的參數(shù):
<div v-html="str" class="ql-editor"> {{str}} </div>
上面的str就是轉(zhuǎn)碼函數(shù)返回的值,我們要先在data中定義,所以我現(xiàn)在將新增跟展示放在一起,代碼如下:
<template> <div class="edit_container"> <!-- 新增時(shí)輸入 --> <quill-editor v-model="content" ref="myQuillEditor" :options="editorOption" @blur="onEditorBlur($event)" @focus="onEditorFocus($event)" @change="onEditorChange($event)"> </quill-editor> <!-- 從數(shù)據(jù)庫(kù)讀取展示 --> <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(){}, // 失去焦點(diǎn)事件 onEditorFocus(){}, // 獲得焦點(diǎn)事件 onEditorChange(){}, // 內(nèi)容改變事件 // 轉(zhuǎn)碼 escapeStringHTML(str) { str = str.replace(/</g,'<'); str = str.replace(/>/g,'>'); return str; } }, computed: { editor() { return this.$refs.myQuillEditor.quill; }, }, mounted() { let content = ''; // 請(qǐng)求后臺(tái)返回的內(nèi)容字符串 this.str = this.escapeStringHTML(content); } } </script>
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- vue-quill-editor富文本編輯器超詳細(xì)入門(mén)使用步驟
- vue使用vue-quill-editor富文本編輯器且將圖片上傳到服務(wù)器的功能
- 淺談vue中使用編輯器vue-quill-editor踩過(guò)的坑
- 解決Vue的文本編輯器 vue-quill-editor 小圖標(biāo)樣式排布錯(cuò)亂問(wèn)題
- Vue+Element UI+vue-quill-editor富文本編輯器及插入圖片自定義
- 詳解Vue基于vue-quill-editor富文本編輯器使用心得
- Vue項(xiàng)目中quill-editor帶樣式編輯器的使用方法
- Vue?quill-editor?編輯器使用及自定義toobar示例詳解
相關(guān)文章
詳解VS Code使用之Vue工程配置format代碼格式化
這篇文章主要介紹了詳解VS Code使用之Vue工程配置format代碼格式化,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-03-03VUE使用axios調(diào)用后臺(tái)API接口的方法
這篇文章主要介紹了VUE使用axios調(diào)用后臺(tái)API接口的方法,文中講解非常細(xì)致,代碼幫助大家更好的理解和學(xué)習(xí),感興趣的朋友可以了解下2020-08-08詳解vue3.0 的 Composition API 的一種使用方法
這篇文章主要介紹了vue3.0 的 Composition API 的一種使用方法,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-10-10Vue2路由動(dòng)畫(huà)效果的實(shí)現(xiàn)代碼
本篇文章主要介紹了Vue2路由動(dòng)畫(huà)效果的實(shí)現(xiàn)代碼,可以根據(jù)不同的路徑去改變動(dòng)畫(huà)的效果,有興趣的可以了解一下2017-07-07一個(gè)因@click.stop引發(fā)的bug的解決
這篇文章主要介紹了一個(gè)因@click.stop引發(fā)的bug的解決,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2019-01-01