I am currently working on consuming an API using axios.
Here is the code I have so far:
<select>
<option v-for="value in values"> value.name </option>
</select>
// js
data(){
values: [],
},
created() {
this.getData();
},
methods: {
getData: () => {
axios.get('url')
.then(res => {
this.value = res.data.dados;
console.log(res.data.dados);
})
.catch(error => {
console.log(error);
});
}
}
The console.log
inside the promise is displaying results, but the options with data are not rendering.
It seems like my select component is being rendered before 'getData()' is called. How can I resolve this issue?