<li @click="changeSort">
价格
<van-icon name="arrow-down" v-show="sortKey==1" />
<van-icon name="arrow-up" v-show="sortKey==2" />
</li>
sortKey: 0, //0原始数据,1升序 2降序
computed: {
//过滤函数的操作
getGoods() {
let goods = [];
goods = this.list.filter((item, index) => {
return item.cid == this.c_id;
});
//按照价格进行升序或降序排列
if (this.sortKey > 0) {
//价格排序用数组的sort方法
goods.sort((a, b) => {
return this.sortKey == 1 ? a.price - b.price : b.price - a.price;
});
}
return goods;
}
},