| |
| import { createApp } from "vue"; |
| import App from "./App.vue"; |
| |
| import store from "./store"; |
| |
| const app = createApp(App); |
| |
| useAnt(app); |
| store.forEach(({ modelName, key }) => { |
| app.use(modelName, key); |
| }); |
| .mount("#app"); |
| |
| import appStore, { key as appKey } from "./modules/app"; |
| |
| const modules = [ |
| { |
| modelName: appStore, |
| key: appKey |
| }, |
| |
| |
| |
| |
| ]; |
| |
| export default modules; |
| |
| import { InjectionKey } from "vue"; |
| import { createStore, useStore as baseUseStore, Store } from "vuex"; |
| |
| export interface State { |
| now: number; |
| } |
| export const key: InjectionKey<Store<State>> = Symbol(); |
| |
| export default createStore<State>({ |
| state: { |
| now: Date.now() |
| }, |
| mutations: { |
| setNow(state, data: number) { |
| state.now = data; |
| } |
| }, |
| actions: {} |
| }); |
| |
| export function appStore() { |
| return baseUseStore(key); |
| } |
参考:
1、TypeScript 支持
2、https://github.com/vuejs/vuex/issues/1833#issuecomment-736418224