我需要编写一个自定义过滤搜索、排序和分页属性,因为我的产品不能依赖任何开箱即用的解决方案,主要是因为我需要在表中显示图像、图标、按钮和urls。把它想象成一个包含图片和购买链接的产品列表页面。
我的问题是如何链接多个计算属性?
示例
用于筛选搜索:
computed: {
filteredProds:function() {
return this.prodlist.filter(prod => {
return prod.name.toLowerCase().includes(this.search.toLowerCase())
})
}为了对表进行排序,我有一个计算过的属性,还有一个进行排序的方法。
myprods.sort((a,b) => {
let modifier = 1;
if(this.currentSortDir === 'desc') modifier = -1;
if(a[this.currentSort] < b[this.currentSort]) return -1 * modifier;
if(a[this.currentSort] > b[this.currentSort]) return 1 * modifier;
return 0;
});发布于 2018-05-05 03:37:16
和引用它们一样简单
data: {
numbers: [1,2,3]
},
computed: {
oddNumbers () {
return this.numbers.filter(n => n % 2)
},
firstOddNumber () {
return this.oddNumbers[0]
}
}https://stackoverflow.com/questions/50185265
复制相似问题