const {ctx} = getCurrentInstance()
来源:19-5 globalProperties - 巧用(下)

ing2042760
2021-04-30
老师,我请教一下,我看网上博客说getCurrentInstance()中的{ctx}开发环境和打包后的生产环境的属性是完全不一样的,我看官方文档也推荐使用internalInstance.appContext.config.globalProperties获取全局挂载的属性,还有博客说使用proxy代替ctx的.
import { getCurrentInstance } from ‘vue’
const MyComponent = {
setup() {
const internalInstance = getCurrentInstance()
internalInstance.appContext.config.globalProperties // 访问 globalProperties
}
}
写回答
2回答
-
春去_秋来
2021-06-10
这样写起来好长啊。不科学啊
00 -
河畔一角
2021-05-13
没怎么听过。目前官方文档上是这么用的,vue-router的源码也是这么挂载的。
00
相似问题