// main.ts声明(需要挂载前定义)
app.config.globalProperties.$test = 'hello world!!'
app.mount('#app')
// 在页面setup内调用
import { getCurrentInstance } from 'vue';
setup() {
const { proxy } = getCurrentInstance();
console.log(proxy.$test); // 打印hello world!!
}
在组件模板调用
<p>globalProperties全局变量:{{ $test }}</p>
vue3访问全局globalProperties
于 2022-02-26 00:52:46 首次发布