_getGoodsData(type) {
const page = this.data.goods[type].page + 1
getGoodsData(type, page).then(res => {
const list = res.data.data.list
const oldList = this.data.goods[type].list
oldList.push(...list) //不用伪数组的话会变成一个二维数组
const listText = `goods.${type}.list` //用反引号解析变量拼接字符串
const pageText = `goods.${type}.page`
this.setData({
[listText]: oldList, //用中括号包裹字符串的变量名才会被解析
[pageText]: page
})
})
},
goods数据格式是:
goods: {
'pop': {
page: 0,
list: []
},
'new': {
page: 0,
list: []
},
'sell': {
page: 0,
list: []
},
}
},