filteredAndOrderedList () {
let list = [...this.list]; //為什麼這裡要解構賦值?
// 按品牌过滤
if (this.filterBrand !== '') {
list = list.filter(item => item.brand === this.filterBrand);
}
// 按颜色过滤
if (this.filterColor !== '') {
list = list.filter(item => item.color === this.filterColor);
}
// 排序
if (this.order !== '') {
if (this.order === 'sales') {
list = list.sort((a, b) => b.sales - a.sales);
} else if (this.order === 'cost-desc') {
list = list.sort((a, b) => b.cost - a.cost);
} else if (this.order === 'cost-asc') {
list = list.sort((a, b) => a.cost - b.cost);
}
}
return list;
}
沒有留言:
張貼留言