全局挂载 变量-函数
main.ts
import { createApp } from 'vue';
import App from './App.vue';
const app = createApp(App);
app.config.globalProperties.$myData = () => {
return {
name: 'name',
}
}
app.mount('#app');
使用
HelloWorld.vue
<script setup lang="ts">
import { ComponentInternalInstance, getCurrentInstance } from "vue";
const { proxy } = getCurrentInstance() as ComponentInternalInstance;
console.log(proxy?.$myData());
</script>
<template>
<div>
test
</div>
</template>
<style scoped>
</style>