Props the value of the transmission is clear to all
# # # #prps can pass a number
# # # #prps can pass a Boolean value
# # # #prps can pass an array
# # # #prps can pass an object
# # #prps can pass all the properties of an object
Today, we are confronted with the problems that are required when passing objects.
Problem:
1. From the parent component came the
props[' info '//info is an array, and each item is an object
Which I need to use info[0].id//This value
So I was mounted:{.
this.id= this,info[0].id//////////////error, reported unfinded
}
and print info is not printed.
The reason is the problem of updating values asynchronously
That is, there is a default value at the beginning, this default value will be changed by the asynchronous data, such as the asynchronous data returned by the object, if you use props way to pass this data, in fact, the first pass the null value, the second pass is the updated value, so there is reported not found error.
Workaround:
Since the first time is null, it will handle ". Items[0", then we can not be in the HTML to determine whether this is not empty (or in computed or watch to determine if the default value) My solution is to watch, listen to this value let ID = this , Info && this.info[0] && this.info[0].id will only be assigned if the ID has a value!!!!!!!!!! It's been a long time, but it's okay to find out
vue-Parent Component Props (object) to child component