<select v-model="cursos" id="cursos" class="form-control" name="cursos">
<option v-for="item in ListaDeCursos" :value="item.from">
{{item.from}}
</option>
</select>
<select v-model="cursos" id="cursos" class="form-control" name="cursos">
<option v-for="item in ListaDeCursos" :value="item.from">
{{item.from}}
</option>
</select>
The Basic Usage > Select section of the documentation addresses this issue:
If the initial value of your v-model expression does not match any of the options, the element will render in an unselected state
Free translation:
If the initial value of the expression in
v-model
does not match any of<option>
, the<select>
element will render in an unselected state.
For this, just give a valid value to v-model
. Example:
new Vue({
el: '#app',
data: {
opcoes: ['Opção 1', 'Opção 2', 'Opção 3'],
selecionado: 'Opção 2'
}
});
<script src="https://cdn.jsdelivr.net/npm/vue"></script><divid="app">
<select v-model="selecionado">
<option v-for="opcao in opcoes" :value="opcao">
{{ opcao }}
</option>
</select>
</app>
Please try the code below.
The idea is to check if the index of the item is 0. If it is, check the option as selected.
<select v-model="cursos" id="cursos" class="form-control" name="cursos">
<option v-for="(item, index) in ListaDeCursos" :value="item.from" :selected="index == 0">
{{item.from}}
</option>
</select>
At the end of the code where you finish loading the list, grab the first element from the list
this.cursos = array[0]