K
K
kimqar_ver2021-04-13 15:57:26
Vue.js
kimqar_ver, 2021-04-13 15:57:26

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);
                        }
                    }
                )
            }

and layout that filters and works properly:
<select v-model="sortBy">
        <option value="PriceMinMax">
                   От мин. до макс.
        </option>

         <option value="PriceMaxMin">
                   ОТ макс. до мин.
         </option>
</select>

How to properly convert select into a bulleted list ul li so that filtering works?
I tried to write like this, it doesn't work:
<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

1 answer(s)
0
0xD34F, 2021-04-13
@kimqar_ver

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 question

Ask a Question

731 491 924 answers to any question