0
Is there any way I can ask for the Vuejs wait a while before dealing with the mistakes of the GIFT?
I have for example a select
who receives a v-model
coming from the API, but as Vuejs loads the DOM first before the call http
, it already accuses error in select
type check failed for prop "options". Expected Array, got Undefined.
That mistake is right because he draws the GIFT with nothing on select, but then he fills in with my call to API. Can I ask Vuejs to wait a while for me to bring the data from API and then he checks the GIFT?
Thank you!!
Note: I know that starting the parameter with empty array works, but wanted another way without being manual
@Edit
.Vue
<vue-select track-by="Value" v-model="data.nome" label="Name" :options="data.nomeList"></vue-select>
data(){
data: {}
}
.Js
axios.get('url.com').then(response => {
this.data= response.data;
})
Post the code...
– Rafael Augusto
There are several ways to control this flow/logic before there is data to show or render. Show the components where you have the problem to understand better. But you could have a
v-if="select.options"
in the parent component.– Sergio
@Rafaelaugusto doesn’t have much to post... but anyway, I put an example there. @Sergio putting one
v-if
to check whether thev-model
empty is a way out, but it’s still very manual... there’s another way? =/– Jackson
In the
data
thatnomeList
should benomeList: []
. How do you get it there?– Sergio
Exactly @Sergio, I don’t have
nomeList
defined, and neither want, because it is very manual remember all parameters and initialize one by one. Thatarray
comes from the API. You can do Vue waiting for the callhttp
before presenting the error of expects an array in my input?– Jackson
In Vue the recommended way is to set this in
data
. You could do:options="data.nomeList || []"
but I advise against it because I find it useful to define what is reactive indata
and thus have information of what properties are used by the component.– Sergio
Got it Sergio!! Thank you :)
– Jackson