vuex与computed有时有效,有时无效没有更新页面

新手上路,请多包涵

1.两个相同的功能,同样的方法,一个有效,一个无效
2.无效的代码:

<Row :gutter="10" style="margin-top: 10px" v-for="(col, index) in categoryList" :key="index">
    <Col span="4" v-for="(item, index) in col" :key="index">
        <category-info :info="item"></category-info>
    </Col>
</Row>
mounted() {
    this.getCategoryList()
},
computed: {
    categoryList() {
        let list = _.chunk(this.$store.state.category.categoryList, 6)
        return list
    },
    categoryTotal() {
        return this.$store.state.category.categoryTotal
    }
},
methods: {
    getCategoryList() {
        this.$store.dispatch('getCategoryList')
    }
}

3.categoryInfo

props: {
    info: Object,
},

4.store

const category = {
    state: {
        categoryList: [],
        categoryTotal: 0,
    },
    mutations: {
        GETCATEGORYLIST (state, data) {
            state.categoryTotal = data.data.length
            let categoryList = data.data
            state.categoryList = categoryList
        },
        DELETECATEGORY (state, typeId) {
            state.categoryTotal--
            state.categoryList = _.remove(state.categoryList, v => {
                return v.typeId != typeId
            })
        }
    },
    actions: {
      // category
        getCategoryList (context) {
            Util.ajax
            .get('/type/all')
            .then(res => {
                context.commit("GETCATEGORYLIST",res.data)
            })
        },
        deleteCategory (context, typeId) {
            Util.ajax
            .delete(`/type/delete?typeIds=${typeId}`)
            .then(res => {
                if(res.data.status == 0) {
                    context.commit("DELETECATEGORY", typeId)
                  }
            })
        },
    }
}

export default category

刷新页面->mounted->重新获取数据,这个时候 store 是有数据的变化的,但是页面是空白

同样的方式另外一个产品列表就是有效的,很奇怪,是因为computed的对象是数组的原因吗?还是写法上有什么问题

阅读 6.3k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题