download:JavaScript高级玩法,成为精通JS的原生专家
【响应数据的处置】如何将响应的商品列表数据依照对应的类别,放到数组中
恳求了商品列表的接口
getGoodsList() {
this.axios
.post('/shop/goods/list/v2', {
categoryId: ['263919', '263920', '263921', '263923', '269499', '263924', '263925', '263926', '263927', '263975'],
})
.then(res => {
this.goodsList.push(res.result)
})
},
需求:把响应的数据以每个类别放到数组中,便当渲染
我运用了以下办法:
// 获取 商品列表
getGoodsList() {
const CATEGORY_ID = ['263919', '263920', '263921', '263923', '269499', '263924', '263925', '263926', '263927', '263975']
for (var i =0; i < CATEGORY_ID.length; i++) {
this.axios
.post('/shop/goods/list/v2', {
categoryId: CATEGORY_ID[i],
pageSize:6,
})
.then(res => {
this.goodsList.push(res.result)
})
}
},
{{item.name}} {{item1.name}} {{item1.minPrice}}元
E64142CA-62D4-49AF-9A9C-9B7E33804D8F.png
但响应的数据并没有依照我恳求参数的次第来停止排序,招致商品列表与分类不相同