【发布时间】:2021-04-19 14:29:03
【问题描述】:
我正在为我的 Vue.js 应用程序创建一个按选择排序的选项,并试图弄清楚如何将选定的值传递给计算函数。我可以让函数使用数组中的硬编码值进行排序,但我想提前通过用户输入传递排序顺序,例如按“价格”排序
通过一些研究,我发现了一些关于传递值的帖子,但无济于事。任何帮助将不胜感激。
工作代码
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})
},
},
迄今为止尝试了所有人的代码,但没有任何乐趣。
【问题讨论】:
标签: javascript vue.js