I have a select drop-down which displays the data either alphabetically or by relevance. It works okay but the issue I have is the data doesn't display when the page loads. It only displays after I have made a selection on the drop-down menu.
I tried adding variations of'this.sortItems();' this.sortatoz();and to mounted but this did not help.
What am I missing?
<select v-model="sortatoz" @change="sortItems">
<option disabled value="" selected>Select</option>
<option value="alphabetically">Alphabetically</option>
<option value="relevance">Relevance</option>
</select>
<div v-for="element in copiedList" :key="element">
<div>{{ element }}</div>
</div>
Computed:
sortItems() {
if (this.sortatoz === "alphabetically") {
this.copiedList = [...this.list].sort((a, b) => (a > b ? 1 : -1));
} else {
if (this.sortatoz === "relevance") {
this.copiedList = [...this.list];
}
}
},
return {
list: ["A", "C", "B"],
copiedList: [],
this. copiedList?this.listis populatedthis.listis populated, and when