Asynchronously requested data will be rendered twice! The first time is when the request is not completed. At this time, obj is returned by you''. Then when the subcomponent gets the value, an error must occur! The second time is when the request is returned, and then there is data. So the solution is obvious, there are many solutions.
Initially, dataObj is a null character, so an error will definitely be reported when passed to the subcomponent. You can use v-if to determine whether the data has been obtained, and then render it after obtaining it.
In addition, it is recommended that the author try to select the appropriate data type and assign the default value when reserving the initial item in the data option. For example, the dataObj in the parent component should store an array type. Try to dataObj: [], so that the semantic expression is also clear.
The subcomponent initially got an empty string and did not have attributes such as .acount.name, so an error occurred.
Easiest solution:
in parent component App.vueChanged to:
Asynchronously requested data will be rendered twice! The first time is when the request is not completed. At this time, obj is returned by you''. Then when the subcomponent gets the value, an error must occur! The second time is when the request is returned, and then there is data. So the solution is obvious, there are many solutions.
Initially, dataObj is a null character, so an error will definitely be reported when passed to the subcomponent. You can use v-if to determine whether the data has been obtained, and then render it after obtaining it.
1. As mentioned above, use v-if to determine dataObj.length in the dom to ensure rendering when there is data (recommended!!)
2. Set the data structure of the dataObj object in the parent component data option in advance, such as:
In addition, it is recommended that the author try to select the appropriate data type and assign the default value when reserving the initial item in the data option. For example, the dataObj in the parent component should store an array type. Try to
dataObj: []
, so that the semantic expression is also clear.