我的模块中名为ShopItemCategory的Getter
getters: {
shopItemsCategories: state => state.ShopItemsCategories.data,
},
这是我在组件内部计算的函数
computed: {
shopItemsCategories() {
return this.$store.getters['ShopItemCategory/shopItemsCategories'].filter(c => c.shop_id == this.$route.params.id)
},
},
当我单击保存时,过滤器工作正常,但刷新后出现错误
Vue warn]: Error in render: "TypeError: Cannot read property 'filter' of undefined"
这就是在马匹上发送的变异
mutations: {
SET_SHOP_ITEM_CATEGORIES(state, shopItemsCategories) {
state.ShopItemsCategories = shopItemsCategories;
},
}
这是组件中mounted()内部的分派命令
mounted() {
this.$store.dispatch('ShopItemCategory/getShopItemsCategories');
},
发布于 2020-05-11 08:22:45
在执行SET_SHOP_ITEM_CATEGORIES
变异之前,getter将使用模块的state
中的任何初始数据。如果未定义ShopItemsCategories.data
属性,则在执行计算属性时将收到报告的错误消息。
简单的解决方案是定义一些对应用程序其余部分有意义的初始状态。
例如
state: {
ShopItemsCategories: {
data: []
}
}
https://stackoverflow.com/questions/61720309
复制相似问题