【发布时间】:2022-08-02 15:38:01
【问题描述】:
我的 Vue 应用程序中有一组结果。我希望能够在搜索后按字母顺序对它们进行排序。然后,我还希望它们返回到我单击“按字母顺序”之前的状态。就我而言,它的相关性。
相关性是它的加载方式以及在我选择“按字母顺序”之前
按字母顺序排列的选项效果很好,但是当我将它改回“相关性”时,它什么也没做,我不明白为什么。对我来说,它应该只是 \'return this.results();\'
有人可以帮忙吗?
<select
class=\"form-control col-4 col-lg-5\"
v-model=\"sortatoz\"
@change=\"sortItems\"
id=\"sortby\"
aria-label=\"sortby\"
>
<option disabled value=\"\" selected>Select</option>
<option value=\"alphabetically\">Alphabetically</option>
<option value=\"relevance\">Relevance</option>
</select>
//sort drop down
sortItems() {
if (this.sortatoz === \"alphabetically\") {
return this.results.sort((a, b) =>
a.title > b.title ? 1 : -1
);
} else {
return this.results();
}
},
标签: vue.js