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的对象是数组的原因吗?还是写法上有什么问题