1 | app.config.globalProperties.foo = 'bar' |
添加可以在应用程序内的任何组件实例中访问的全局 property。属性名冲突时,组件的 property 将具有优先权。
这可以代替 Vue 2.x Vue.prototype
扩展:
1 | // 之前(Vue 2.x) |
官方文档:https://www.vue3js.cn/docs/zh/api/application-config.html#globalproperties
值得注意的是:而在3.0的settup中是没有this的!!!
1 | import { getCurrentInstance,onBeforeMount} from 'vue'; |