vue3使用this

vue3提供了getCurrentInstance ,通过这个属性,找到全局属性globalProperties
import { getCurrentInstance } from 'vue'
const instance = getCurrentInstance()
const _this= instance.appContext.config.globalProperties

这个_this就可以当vue2.x的this用了

如在elementUI:_this.$message.error('error')
posted @ 2021-07-08 19:03  zzwlong  阅读(7361)  评论(0编辑  收藏  举报