Vuex:状态更新,但计算属性不是

时间:2018-06-05 13:44:03

标签: vue.js vuejs2 vuex

我有一个组件,它带有一个名为' endpoints'从商店,稍微调整一下......

computed: {
            ...mapState(['endpoints']),
            adjustedEndpoints () {
                if (this.endpoints){
                    return this.endpoints.map(x => {
                        x.displayName = x.name;
                        return x;
                    })
                }
            },

...并将其传递给模板中的表组件:

    <b-table show-empty
             stacked="md"
             :items="adjustedEndpoints"
             :fields="fields"
             :current-page="currentPage"
             :per-page="perPage"
             :filter="filter"
             :sort-by.sync="sortBy"
             :sort-desc.sync="sortDesc"
             :sort-direction="sortDirection"
             @filtered="onFiltered"
    >

问题在于,当我编辑端点的属性时,我看到它在Vue组件状态中发生了变化,但在重新加载之前,这不会反映在渲染的组件中。我猜测adjustEndpoints()函数没有被自动调用。

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:2)

发现问题。

在Vuex商店的初始状态中,我没有声明'endpoints'属性。

这就是整个问题。

相关问题