【发布时间】:2021-10-31 21:45:40
【问题描述】:
我正在开发一个产品概览页面,该页面根据您正在查看的当前类别发送 API 调用:
store.dispatch("tweakwise/fetchAPIAttributesLayeredNavigation", {
tweakwiseCategory,
this.pageNumber,
}
在我的商店中,来自此 API 调用的数据将设置为以下 VueX 商店状态:
this.$store.state.tweakwise.tweakwiseLayeredNavigationAttributes: []
我想在前端对这些数据做出反应,但我的计算方法似乎对这种变化没有反应。正如您在下面的函数中看到的那样,我添加了一个 Catch 来防止“未定义”错误。但是,在设置状态后将不会调用该函数。 这个计算属性也被添加到组件的 Mount() 操作中
computed: {
initialFetchProducts() {
this.fetchProducts(
this.$store.state.tweakwise?.tweakwiseLayeredNavigationAttributes || []
);
},
},
【问题讨论】:
标签: vue.js dynamic state vuex store