0
点赞
收藏
分享

微信扫一扫

vue3访问全局globalProperties

Go_Viola 2022-02-26 阅读 167
vue.js
// main.ts声明(需要挂载前定义)
app.config.globalProperties.$test = 'hello world!!' 
app.mount('#app')

// 在页面中调用
import { getCurrentInstance } from 'vue';
const { proxy } = getCurrentInstance();
console.log(proxy.$test); // 打印hello world!!
举报

相关推荐

0 条评论