import { InjectionKey } from 'vue' import { createStore, useStore as baseUseStore, Store } from 'vuex' // 为 store state 声明类型 export interface State { num: number } // 定义 injection key export const key: InjectionKey> = Symbol() export const store = createStore({ state: { num: 888 }, mutations: { setNum (state: State, num: number) { state.num = num } }, getters: { getNum (state: State) { return state.num } } }) // 定义自己的 `useStore` 组合式函数 export function useStore () { return baseUseStore(key) }