Reputation: 427
I need to write a custom filtered search, sort and paginate properties since my product cannot rely any of the out of box solutions mainly because I need to display images, icons, buttons and urls in my table. Think of it as a product listing page with images and buy links.
My question is how do I chain multiple computed properties?
For Filtered Search:
computed: {
filteredProds:function() {
return this.prodlist.filter(prod => {
return prod.name.toLowerCase().includes(this.search.toLowerCase())
})
}
and for sorting the table I have this computed property along with a method to do the sort.
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;
});
Upvotes: 1
Views: 988
Reputation: 3466
As simple as referencing them
data: {
numbers: [1,2,3]
},
computed: {
oddNumbers () {
return this.numbers.filter(n => n % 2)
},
firstOddNumber () {
return this.oddNumbers[0]
}
}
Upvotes: 3