I
I
Igor Bodyagin2020-08-13 17:35:46
Vue.js
Igor Bodyagin, 2020-08-13 17:35:46

Why is Vue's Selected property not working?

Why is the selected property not working on a Vue select option element?

The code:

<label>
                  Категория
                  <select v-model="Category" id="categoryTop"
                          class="select_category">
                    <option value="Большие" selected>Большие</option>
                    <option
                        v-for="cat in categoryOptions"
                        :value="cat"
                    >{{ cat }}</option>
                  </select>
                </label>


As a result, everything is displayed normally, but the input is empty, but you need the first element to be the default.
I noticed that for some reason Vue sets the value selected="selected" and it doesn't work, but if it's easy to set the handles in chrome dev tools: then everything works.
<option val="Пример" selected>Пример</option>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2020-08-13
@IgorBod

because

v-modelignores the initial value of attributes value, checkedor selectedon any form elements.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question