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')
原文地址:https://www.cnblogs.com/zzwlong/p/14987695.html