如何使用 vuex 在 vue 3 中使我的商店在全球范围内可用?
我的店铺:
import { createStore } from 'vuex'
export default createStore({
state: {},
mutations: {},
getters: {},
actions: {},
modules: {},
})
我的 main.ts
import yourStore from './store/yourStore'
const app = createApp(App)
app.use(yourStore)
app.config.globalProperties.$yourStore = yourStore
app.mount('#app')
这不起作用:
this.$yourStore.dispatch('your action')