vue項目使用富文本編輯器vue-quill-editor的方法介紹

1. 使用npm或者yarn安裝 `vue-quill-editor` 插件, 命令行 :? npm install?vue-quill-editor? 或? yarn add vue-quill-editor

2. 在我們的vue項目src文件夾下的 `main.js` 中引入富文本編輯器 , 代碼如下 :?

????import VueQuillEditor from 'vue-quill-editor';

????import 'quill/dist/quill.core.css';

????import 'quill/dist/quill.snow.css';

????import 'quill/dist/quill.bubble.css';

????Vue.use(VueQuillEditor);

3. 在我們需要使用富文本編輯器的組件中 , v-model去動態(tài)綁定我們輸入的內(nèi)容 ,? options修改富文本編輯器相關設置

<quill-editor v-model="submitFromDataSummary.summary" style="width: 100%; height: 300px" :options="editorOption">

</quill-editor>

4. 在data中添加editorOption , 修改富文本編輯器的相關設置

editorOption: {

? modules: {

? ? toolbar: 'title'? ? // 設置文本編輯器的頭部是否展示

? },

? placeholder: '文本占位',? ? // 文本框為空時 , 占位文本

? theme: 'snow'? ? // 或者為 `bubble`

}

5. 在我們提交文本內(nèi)容之前先使用正則去識別空格 , 換行... summary為textarea輸入的內(nèi)容

const content = this.content.eplace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>').replace(/\s/g, '&nbsp;');

6. 在需要展示文本的地方, 使用v-html去綁定

<div v-html="content"></div>

?著作權歸作者所有,轉載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容