[转]element中this.$message 失效问题解决方法(使用全局调用,重新定义this)(转载请删除括号里的内容)
element
A Vue.js 2.0 UI Toolkit for Web
项目地址:https://gitcode.com/gh_mirrors/eleme/element
·
这两天写项目的时候发现了这个问题。
问题再现:在Model框中操作数据,在使用this.$message进行消息提示时发现,提示框失效
。
本人解决方案(具体原因我没有找出来,写这个出来也是为了让大佬指点指点)
// 保存修改数据
handleSaveMu(row) {
let srcColumnSqc = row.srcColumnSqc;
let tarColumnName = row.tarColumnName;
let tarColumn = row.tarColumn;
let tarColumnType = row.tarColumnType;
let id = row.id
let apiType = this.muFormData.apiType;
let srcTable = this.muFormData.srcTable;
let jobName = this.muFormData.jobName;
editMuTable(apiType,srcTable,srcColumnSqc,tarColumnName,tarColumn,tarColumnType,jobName,id).then(res=>{
//console.log(res)
if(res.data.code ==200){
this.$message.success(res.data.msg) //数据请求成功,this.$message方法失效
this.checkMuVisible=false
this.editDisabled2 = true
}else{
this.$message.error(res.data.msg)
this.editDisabled2 = false
}
})
},
解决方案一:
可以看到后台返回的数据使用this.$message就会失效,因为 this 指的不再是Vue了,所以… …
Vue.prototype.$message({
message: '成功!',
type: 'success'
});
使用全局变量Vue.prototype来调$message()就可以了。
解决方案二:
或者重新定义this也是可以的。如下:
handleSaveMu(row) {
let _this = this; //重新定义this
let srcColumnSqc = row.srcColumnSqc;
let tarColumnName = row.tarColumnName;
let tarColumn = row.tarColumn;
let tarColumnType = row.tarColumnType;
let id = row.id
let apiType = this.muFormData.apiType;
let srcTable = this.muFormData.srcTable;
let jobName = this.muFormData.jobName;
editMuTable(apiType,srcTable,srcColumnSqc,tarColumnName,tarColumn,tarColumnType,jobName,id).then(res=>{
//console.log(res)
if(res.data.code ==200){
_this.$message.success(res.data.msg)
_this.checkMuVisible=false
_this.editDisabled2 = true
}else{
_this.$message.error(res.data.msg)
_this.editDisabled2 = false
}
})
},
---------------------
作者:ZHANGJIN9546
来源:CSDN
原文:https://blog.csdn.net/ZHANGJIN9546/article/details/103807180
版权声明:本文为作者原创文章,转载请附上博文链接!
A Vue.js 2.0 UI Toolkit for Web
最近提交(Master分支:3 个月前 )
c345bb45
1 年前
a07f3a59
* Update transition.md
* Update table.md
* Update transition.md
* Update table.md
* Update transition.md
* Update table.md
* Update table.md
* Update transition.md
* Update popover.md 1 年前
AtomGit 是由开放原子开源基金会联合 CSDN 等生态伙伴共同推出的新一代开源与人工智能协作平台。平台坚持“开放、中立、公益”的理念,把代码托管、模型共享、数据集托管、智能体开发体验和算力服务整合在一起,为开发者提供从开发、训练到部署的一站式体验。
更多推荐



所有评论(0)