app.vue
<template>
{{ info.a }}
<div @click="onChangeInfo">获取数据</div>
</template>
<script lang="ts">
import { defineComponent, getCurrentInstance, ref, onMounted } from "vue";
function InfoModule(self: any) {
const info = ref({});
const onChangeInfo = () =>
self.$store.dispatch("DEMO_DETAIL_API").then((dd: any) => {
info.value = dd;
});
return { info, onChangeInfo };
}
export default defineComponent({
setup(props) {
const { proxy }: any = getCurrentInstance();
const infoToRefs = InfoModule(proxy);
onMounted(() => {
console.log("onMounted", props, proxy.$root);
infoToRefs.onChangeInfo()
});
return {
...infoToRefs,
};
},
});
</script>
main.ts
import { createApp } from 'vue';
import App from './App.vue';
import router from './router';
import store from './store';
import parentTool, * as tool from './prototype';
const app: any = createApp(App)
// console.log('tool', tool)
Object.assign(app.config.globalProperties, parentTool, tool, { __foo: '11' })
declare module '@vue/runtime-core' {
interface ComponentCustomProperties {
[index: string]: unknown;
}
}
app
.use(store)
.use(router)
.mount('#app');