总结Vue父子组件相互传值和路由传值的两种方式【后续更新】

1、父到子

思路总结:

     1、定义子组件接收父组件的变量在props['child'],的单独的属性中,与data()平行;

     2、在父组件中给子组件中定义的变量赋值==>  :child="parentMessage"    parentMessage为父组件响应系统中的变量

2、子到父

1、父组件自定义指令,如: @Transfer=show

2、子组件想父组件的指令进行传值,如 :this.$.emit('transfer',要传的变量=transferValue)

3、父组件指令绑定的方法进行取值,如:在方法中show(传递的变量值=transferValue){ this.a = transferValue},记得在data()中用变量a进行接收;

3、this.$route.params

4、this.$route.query

路由代码:

https://github.com/pshdhx/LearnVueRouter

猜你喜欢

转载自blog.csdn.net/pshdhx/article/details/107535292