首页 > 技术文章 > vue3使用this

zzwlong 2021-07-08 19:03 原文

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')

推荐阅读