Summarize the two ways that Vue parent and child components pass values between each other and route passes [subsequent updates]

1. Father to Son

Summary of ideas:

     1. Define the variable of the child component to receive the parent component in a separate property of props['child'], parallel to data();

     2. Assign a value to the variable defined in the child component in the parent component ==> :child="parentMessage" parentMessage is the variable in the parent component response system

2. Son to Father

1. Parent component custom instructions, such as: @Transfer=show

2. The child component wants the instruction of the parent component to pass the value, such as: this.$.emit('transfer', the variable to be passed = transferValue)

3. The method bound by the parent component instruction is used to obtain the value, such as: in the method show (transferred variable value = transferValue) {this.a = transferValue}, remember to use the variable a to receive in data();

3、this.$route.params

4、this.$route.query

Routing code:

https://github.com/pshdhx/LearnVueRouter

Guess you like

Origin blog.csdn.net/pshdhx/article/details/107535292