1. 程式人生 > >【vue】使用wangeditor富文字編輯器

【vue】使用wangeditor富文字編輯器

前言:

本專案需要一個輕量級的,能夠顯示原始碼的富文字編輯器。

經查詢對比後,選擇wangeditor,但是發現wangeditor3(最新版)中沒有展示原始碼的功能,故選擇wangeditor2。

使用方法:

1.下載:

選擇npm安裝:因為目前預設版本為3.1.1,故安裝的時候需要寫明需要安裝的版本號

npm install [email protected] --save

2.開始使用

<div id="websiteEditorElem" style="height: 250px"></div>
import E from 'wangeditor'
mounted () {
      // wangeditor
      phoneEditor = new E('phoneEditorElem')
      phoneEditor.onchange = function () {
        this.formData.phone = this.$txt.html()
      }
      phoneEditor.create()
    },

實現效果:

1.預設狀態下

2.顯示原始碼