如題,在寫一個后臺文章管理頁面,通過彈出dialog來編輯文章內(nèi)容,正文使用wangEditor來編輯,在編輯按鈕的響應(yīng)方法中加入的wangEditor的創(chuàng)建和配置代碼,結(jié)果如圖:
第一次點擊按鈕后,富文本框不正常顯示;
第二次點擊,顯示一個富文本框;
第三次點擊,顯示兩個個嵌套的富文本框;
第四次,顯示了三個……以此類推。
我的代碼是這么寫的:
彈出對話框按鈕:
<el-table-column label="操作">
<template slot-scope="scope">
<el-button size="small" type="success" @click="editArticle(scope.row)">編輯</el-button>
<el-button size="small" type="info" @click="delArticle(scope.row)">刪除</el-button>
</template>
</el-table-column>
對話框中對富文本框的定義:
<el-dialog title="修改精選文章" :visible.sync="dialogVisible">
<el-form :model="articleInfo" label-width="160px" ref="articleInfo" :rules="articleRules">
<el-form-item label="文章正文:" prop="Content">
<div id="editor" style="text-align:left"></div>
</el-form-item>
</el-form>
</el-dialog>
JS代碼中對對話框按鈕的響應(yīng)方法:
editArticle(row){
this.dialogVisible = true;
this.articleInfo = row;
console.log('row:', this.articleInfo);
//富文本編輯器的代碼
let self = this;
var editor = new E('#editor');
editor.customConfig.onchange = (html) => {
self.articleInfo.Content = html;
};
editor.customConfig.uploadImgServer = '/api/v1/put_file';
editor.customConfig.showLinkImg = false;
editor.customConfig.customUploadImg = function (files, insert) {
// files 是 input 中選中的文件列表
// insert 是獲取圖片 url 后,插入到編輯器的方法
//打印出來的是編輯器獲取到的圖片文件們,是一個圖片文件數(shù)組
// console.log(files);
//循環(huán)依次存儲圖片到服務(wù)器
for(let i=0;i<files.length;i++){
//創(chuàng)建form對象,將文件傳到后端接口
let param = new FormData(); //創(chuàng)建form對象
param.append('file',files[i],files[i].name);//通過append向form對象添加數(shù)據(jù)
//param.append('chunk','0');//添加form表單中其他數(shù)據(jù)
// console.log(param.get('file')); //FormData私有類對象,訪問不到,可以通過get判斷值是否傳進去
let config = {
headers: {'Content-Type': 'multipart/form-data'}
};
myAxios.post('/api/v1/put_file',param,config)
.then(res => {
console.log(res);
let url="http://"+res.data.data.url;
// 上傳代碼返回結(jié)果之后,將圖片插入到編輯器中
insert(url);
})
.catch(err => {
console.log(err)
});
}
};
editor.create();
},
我自己嘗試過在關(guān)閉對話框時添加監(jiān)聽方法,然后關(guān)閉editor,但是無論是editor.close()還是editor.destory()都會提示沒有這個方法,求助。
北大青鳥APTECH成立于1999年。依托北京大學優(yōu)質(zhì)雄厚的教育資源和背景,秉承“教育改變生活”的發(fā)展理念,致力于培養(yǎng)中國IT技能型緊缺人才,是大數(shù)據(jù)專業(yè)的國家
北大青鳥中博軟件學院創(chuàng)立于2003年,作為華東區(qū)著名互聯(lián)網(wǎng)學院和江蘇省首批服務(wù)外包人才培訓基地,中博成功培育了近30000名軟件工程師走向高薪崗位,合作企業(yè)超4
中公教育集團創(chuàng)建于1999年,經(jīng)過二十年潛心發(fā)展,已由一家北大畢業(yè)生自主創(chuàng)業(yè)的信息技術(shù)與教育服務(wù)機構(gòu),發(fā)展為教育服務(wù)業(yè)的綜合性企業(yè)集團,成為集合面授教學培訓、網(wǎng)
達內(nèi)教育集團成立于2002年,是一家由留學海歸創(chuàng)辦的高端職業(yè)教育培訓機構(gòu),是中國一站式人才培養(yǎng)平臺、一站式人才輸送平臺。2014年4月3日在美國成功上市,融資1
曾工作于聯(lián)想擔任系統(tǒng)開發(fā)工程師,曾在博彥科技股份有限公司擔任項目經(jīng)理從事移動互聯(lián)網(wǎng)管理及研發(fā)工作,曾創(chuàng)辦藍懿科技有限責任公司從事總經(jīng)理職務(wù)負責iOS教學及管理工作。
浪潮集團項目經(jīng)理。精通Java與.NET 技術(shù), 熟練的跨平臺面向?qū)ο箝_發(fā)經(jīng)驗,技術(shù)功底深厚。 授課風格 授課風格清新自然、條理清晰、主次分明、重點難點突出、引人入勝。
精通HTML5和CSS3;Javascript及主流js庫,具有快速界面開發(fā)的能力,對瀏覽器兼容性、前端性能優(yōu)化等有深入理解。精通網(wǎng)頁制作和網(wǎng)頁游戲開發(fā)。
具有10 年的Java 企業(yè)應(yīng)用開發(fā)經(jīng)驗。曾經(jīng)歷任德國Software AG 技術(shù)顧問,美國Dachieve 系統(tǒng)架構(gòu)師,美國AngelEngineers Inc. 系統(tǒng)架構(gòu)師。