使用wangEditor富文字編輯器遇到的問題總結
阿新 • • 發佈:2018-12-01
怎麼使用和安裝我就不詳細說了,文件寫得很清楚,https://www.kancloud.cn/wangfupeng/wangeditor3/332599
1、當螢幕縮時,富文字編輯器的選項會被隱藏,如下圖官網的demo:當螢幕變小時,選單選項就超出了富文字編輯器的區域,撤回和恢復已經隱藏不見了
原因,如果我們檢查程式碼就會發現,其實富文字編輯器使用了彈性盒模型(不懂的百度,推薦阮一峰大神的文章:http://www.ruanyifeng.com/blog/2015/07/flex-grammar.html?%5E%25$),display:flex,所以知道了這個問題就簡單了,我們知道,彈性盒模型,預設情況下,專案都排在一行上面,也即超出部分不換行:flex-wrap:nowrap ,所以我們只需要更改編輯器的預設值即可,即新增一條樣式:flex-wrap:wrap
.w-e-toolbar{
flex-wrap:wrap;
}
注意:有時候我們在vue元件內部更改預設樣式不起作用,此時可以在全域性試試就可以了,至於為什麼,我暫時還沒搞明白,如果您知道,歡迎評論區留言告知哦,在此先謝過
就這麼簡單,然後看圖:完美!
問題2:上傳圖片到伺服器中(可以使用base64格式的,但是如果圖片過大,經過base64編譯過後檔案會很大,所以不建議哦)
我封裝了一個函式,可以上傳圖片,可以動態獲取內容,如下:
data(){ return { editContent:''//儲存富文字編輯器的內容 } }, methods:{ wangEdit (id) { let editor = new E(id) editor.customConfig.onchange = (html) => { this.editContent = html//動態獲取富文字編輯器的內容 } editor.customConfig.uploadImgMaxSize = 3 * 1024 * 1024; editor.customConfig.uploadFileName = 'file[]' editor.customConfig.uploadImgServer = '/proxy/platform/photo.moreImgUpload'//換成後端給你的上傳圖片的介面 editor.customConfig.uploadImgHooks = { before: function (xhr, editor, files) { let formdata=new FormData(); for(let i=0;i<files.length;i++){ let url = files[i]; formdata.append('file[]', url) } }, customInsert: function (insertImg, result, editor) { for(let i=0;i<result.data.length;i++){ let url = result.data[i] insertImg(url) } } } editor.create() } } //使用:this.wangEdit(‘#edit’)