ElementuUI this.$notify 封装以后报错 properties of undefined (reading ‘$notify‘)

ElementuUI this.$notify 封装以后报错 properties of undefined (reading ‘$notify‘),第1张

使用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

执行结果:

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1322964.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-12
下一篇 2022-06-12

发表评论

登录后才能评论

评论列表(0条)

保存