在vue中绑定全局原型属性
在vue2中通过导入Vue构造函数再在上面绑定
// main.js
import Vue from "vue"
Vue.prototype.$test = "test"
// 组件中
mounted(){
console.log(this.$test)
}
Vue3中需要使用一些api
// main.js
const app = createApp(App)
app.config.globalProperties.$test = "test"
// 组件中
<script setup>
import { getCurrentInstance } from "vue"
const internalInstance = getCurrentInstance();
const $test = internalInstance.appContext.config.globalProperties.$test;
</script>