vue-Parent Component Props (object) to child component

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.