在使用webpack定义动态组件时,是否可以访问VueX存储getter?
我在我的商店里使用了多个模块。
示例:
components: {
'some-template': () => {
const someVal = this.$store.getters.someVal;
return System.import(`./some-template/${someVal}.vue`)
}
}
Main.js
import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
import { someStore } from ./stores/some-store'
import { otherStore } from ./stores/other-store'
new Vue({
el: '#app',
store: new VueX.Store({
modules: {
someStore,
otherStore
}
})
})
商店示例:
export const someStore = {
state: {
someVal: 'blah'
},
getters: {
someVal(state) {
return state.someVal;
}
}
}
发布于 2020-07-14 06:49:00
为了解决模块的问题,我创建了一个应用程序商店,默认使用新的Vuex实例,然后根据需要动态添加模块。这样,我就可以在需要的地方导入存储并访问getter
https://stackoverflow.com/questions/62844024
复制相似问题