I am creating a sort by select option for my Vue.js app and trying to work out how to pass a selected value to a computed function. I can get the function to sort with a hardcoded value from the array, but I want to work ahead to pass in a sort order by the user input e.g. Sort by 'Price'
With a bit of research I have found some posts about passing in values, but to no avail. Any help would be appreciated.
Working code
computed: {
computedObj() {
return this.endpg
? this.filteredList.slice(this.startpg, this.endpg)
: this.lists;
/* return _.orderBy(this.users, 'name') */
},
filteredList() {
return this.lists.filter((item) => {
return (
item.address.toLowerCase().includes(this.search.toLowerCase()) &&
(this.selectBedrooms.length === 0 || this.selectBedrooms.includes(item.bedrooms))
);
}).sort(function (a, b) {return a.price - b.price})
},
},
Tried everyones code to date but no joy.