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

这样写起来好长啊。不科学啊

0
0

河畔一角

2021-05-13

没怎么听过。目前官方文档上是这么用的,vue-router的源码也是这么挂载的。

0
0

Vue全家桶实战 从零独立开发企业级电商系统

Vue全家桶构建企业级电商系统,真实服务端数据对接,高实用性

2560 学习 · 1307 问题

查看课程