首頁 > web前端 > Vue.js > 主體

vue3怎麼使用vueup/vue-quill富文本並限制輸入字數

PHPz
發布: 2023-05-20 16:16:06
轉載
2670 人瀏覽過

一、效果展示

vue3怎麼使用vueup/vue-quill富文本並限制輸入字數

二、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: &#39;info&#39;,
        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"]
              // [&#39;addBtn&#39;]
            ] // 自定义工具栏选项
          }
        }
      })
      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  }
登入後複製

以上是vue3怎麼使用vueup/vue-quill富文本並限制輸入字數的詳細內容。更多資訊請關注PHP中文網其他相關文章!

相關標籤:
來源:yisu.com
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!