我知道它是.sort(),但我不知道它在下面的代码中的位置。我已经尝试了所有的方法,它要么坏了,要么不工作。在这种情况下,我想按字母顺序排序。
<div id="navBar">
<span v-for="country in countries" :key="country">
<button v-on:click="setCountry(country)">{{ country }}</button>
</span>
</div>
data: {
selectedCountry: ""
},
computed: {
countries() {
return [...new Set(this.hotels.map(h => h.country))]
}
},
methods: {
setCountry(country) {
this.selectedCountry = country === this.selectedCountry
? ''
: country;
this.selectedRegions = [];
}
},
我想这可能有用
computed: {
countries() {
let arr = [...new Set(this.hotels.map(h => h.country))]
return arr.sort()
}
此外,如果这不起作用,那么您的 [...new Set(this.hotels.map(h => h.country))]
看起来像。