使用elemnt的d窗插件时,打算对调用进行一次封装,自动根据响应体改变标题和内容以及类型,
可是封装完进行调用的时候,报错
show-message.js?fac0:7 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading '$notify') at showMessage (show-message.js?fac0:7:1) at eval (user-table.vue?bfe9:392:1)
直接写在当前页面就没有问题
getList() {
this.listLoading = true
getUserList(this.listQuery).then(response => {
console.log(response)
this.list = response.data.item
this.total = response.data.total
this.$notify({
title: 'title',
message: 'res.msg',
type: 'success'
})
})
噢。。后来发现是用this
调用的,那么我封装中的this
应该就不是同一个对象了吧,试着调用的时候传递this。然后js中使用传递的this进行调用
调用:
js
执行结果:
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)