Answer the question
In order to leave comments, you need to log in
How to convert v-model with select to ul li VUE JS?
There is the following code that filters by price tag from maximum to minimum
showedItems: function () {
return this.items.slice(0, this.showedItemsCount).filter((item) => {
return (this.keyword.length === 0 || item.name.includes(this.keyword))
}).sort((a, b) => {
if (this.sortBy == 'PriceMinMax') {
return (a.fullCost-b.fullCost);
}
else if (this.sortBy =='PriceMaxMin') {
return (b.fullCost-a.fullCost);
}
}
)
}
<select v-model="sortBy">
<option value="PriceMinMax">
От мин. до макс.
</option>
<option value="PriceMaxMin">
ОТ макс. до мин.
</option>
</select>
<ul v-model="sortBy">
<li value="PriceMinMax">Сначала дешевле</li>
<li value="PriceMaxMin">Сначала дороже</li>
</ul>
Answer the question
In order to leave comments, you need to log in
data: () => ({
sortOptions: [
{ value: 'PriceMinMax', text: 'сначала дешевле' },
{ value: 'PriceMaxMin', text: 'сначала дороже' },
],
...
}),
<ul>
<li
v-for="n in sortOptions"
v-text="n.text"
:class="{ active: sortBy === n.value }"
@click="sortBy = n.value"
></li>
</ul>
li.active {
color: red;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question