问题描述:已经在标题上了
解决办法:
1:在页面销毁时删除ueditor实例,,mounted时创建实例,这样做的目的是再次进来时重新加载ueditor
mounted() {
// 自定义上传路径
const baseUrl='http://localhost:8080/investment';
UE.Editor.prototype._bkGetActionUrl = UE.Editor.prototype.getActionUrl;
UE.Editor.prototype.getActionUrl = function(action) {
// 对应的是后台upload那个方法
if (action == 'uploadimage' || action == 'uploadscrawl' || action == 'listimage'||action=='uploadvideo') {
return baseUrl+'/fileUpload/uploadForUeditor';
} else {
return this._bkGetActionUrl.call(this, action);
}
}
this.editor = UE.getEditor('editor', this.config); // 初始化UE
// //初始化UE
// const _this = this;
// this.editor = UE.delEditor("editor");
// this.editor = UE.getEditor('editor',this.config);
},
beforeDestroy(){
UE.delEditor('editor');
},
2:正常在这里应该可以解决问题了,但是我ueditor的config.json是从后端加载过来的。在加了上面的代码以后,页面是可以正常显示的,但是上传图片功能费了,说是http无法正常加载什么的,我判断是因为没有正常加载后端的配置(因为这个时候我要是强制刷新,CTRL+R的话,就好了),所以需要想办法让再次进入页面的时候重新从后端加载配置项。。。。。
这个时候就需要改源码了,如下:
文件:ueditor.all.js 。具体修改的代码看我的注释
UE.Editor.prototype.loadServerConfig = function(){
var me = this;
setTimeout(function(){
try{
// me.options.imageUrl && me.setOpt('serverUrl', me.options.imageUrl.replace(/^(.*[\/]).+([\.].+)$/, '$1controller$2'));
// var configUrl = me.getActionUrl('config'),
//isJsonp = utils.isCrossDomainUrl(configUrl);
//杨子栋:为了解决ueditor二次加载不能显示的问题,需要改这里的源码,我注释了8080和8081行,8082原本就是注释的,增加了8083行
var configUrl='http://localhost:8080/investment/ueditor/exec?action=config',
isJsonp = false;
/* 发出ajax请求 */
me._serverConfigLoaded = false;
configUrl && UE.ajax.request(configUrl,{
'method': 'GET',
'dataType': isJsonp ? 'jsonp':'',
'onsuccess':function(r){
try {
var config = isJsonp ? r:eval("("+r.responseText+")");
utils.extend(me.options, config);
me.fireEvent('serverConfigLoaded');
me._serverConfigLoaded = true;
} catch (e) {
showErrorMsg(me.getLang('loadconfigFormatError'));
}
},
'onerror':function(){
showErrorMsg(me.getLang('loadconfigHttpError'));
}
});
} catch(e){
showErrorMsg(me.getLang('loadconfigError'));
}
});
这个问题花了我1个多小时,心酸,特此记录!