vue3使用vueup/vue-quill富文本、并限制輸入字數(shù)的方法處理
vue3中使用富文本實在是踩了太多坑了,大概記錄一下笨方法處理,有好的方法多交流
一、效果展示
二、npm
npm install @vueup/vue-quill@alpha --save
三、main.js引入
import { QuillEditor } from '@vueup/vue-quill' import '@vueup/vue-quill/dist/vue-quill.snow.css'; app.component('QuillEditor',QuillEditor)
四、頁面使用
<quill-editor v-model:content="htmlValue" ref="myQuillEditor" contentType="html" :options="editorOption" @update:content="onEditorChange($event)"> </quill-editor> <div class="editor_length">{{ TiLength }}/500</div>
const htmlValue=ref("") const TiLength =ref(0) const myQuillEditor=ref(null) const editorOption=reactive({ theme: "snow", // 主題 // debug: 'info', placeholder: "請輸入其他說明", modules: { toolbar: { container: [ ["bold", "italic", "underline", "strike"], ["blockquote", "code-block"], [{ header: 1 }, { header: 2 }], [{ list: "ordered" }, { list: "bullet" }], [{ script: "sub" }, { script: "super" }], [{ indent: "-1" }, { indent: "+1" }], [{ direction: "rtl" }], [{ size: ["small", false, "large", "huge"] }], [{ header: [1, 2, 3, 4, 5, 6, false] }], [{ color: [] }, { background: [] }], // [{ font: [] }], [{ align: [] }] // ["clean", "link", "image"] // ['addBtn'] ] // 自定義工具欄選項 } } }) const onEditorChange=(e)=>{ // console.log(myQuillEditor.value.getText().length); // console.log(TiLength.value); TiLength.value =myQuillEditor.value.getText().length-1 if(TiLength.value>500){ myQuillEditor.value.setText(myQuillEditor.value.getText().slice(0,500)) return } } return{ htmlValue,editorOption,onEditorChange,TiLength,myQuillEditor }
五、總結(jié)問題(簡單記錄一下笨方法處理的)
1、雙向綁定:v-model:content(一定加content)
2、change事件:@update:content
3、填寫下一個富文本上一個未清空時: myQuillEditor.value.setHTML('')強制清空一下
4、編輯進入的時候:強制設(shè)置一下內(nèi)容;并且延遲設(shè)置一下字數(shù)
nextTick(()=>{TiLength.value =myQuillEditor.value.getText().length-1 })
到此這篇關(guān)于vue3使用vueup/vue-quill富文本、并限制輸入字數(shù)的文章就介紹到這了,更多相關(guān)vue3使用vueup/vue-quill富文本內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
element-ui 表格數(shù)據(jù)時間格式化的方法
這篇文章主要介紹了element-ui 表格數(shù)據(jù)時間格式化的方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-08-08Vue實現(xiàn)dom元素拖拽并限制移動范圍的操作代碼
這篇文章主要介紹了Vue實現(xiàn)dom元素拖拽并限制移動范圍的操作代碼,本文通過實例代碼給大家介紹的非常詳細,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2023-12-12vue 3.x 中mixin封裝公用方法應(yīng)用方式
這篇文章主要介紹了vue 3.x 中mixin封裝公用方法應(yīng)用方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-05-05vue v-for出來的列表,點擊某個li使得當(dāng)前被點擊的li字體變紅操作
這篇文章主要介紹了vue v-for出來的列表,點擊某個li使得當(dāng)前被點擊的li字體變紅操作,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-07-07Element-ui?DatePicker日期選擇器基礎(chǔ)用法示例
這篇文章主要為大家介紹了Element-ui?DatePicker日期選擇器基礎(chǔ)用法示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2023-06-06