父子路由传参

情况一:router-view 子组件发生变化导致父组件发生改变
父组件中:

<router-view @getMessage="showMsg"></router-view>
showMsg (val) {   // methods方法  val即为子组件传过来的值
  console.log(val)
}

子组件中:

this.$emit('getMessage', “传给父组件的值”);
1
情况二:router-view 父组件发生变化导致子组件发生改变

父组件中:

<router-view  :searchVal="searchVal"></router-view>
searchVal: '',  // data里面申明
this.searchVal = ‘需要传给子组件的值’;    // 在需要传值的方法中处理

子组件中:

props: ['searchVal'],

watch: {
      searchVal: function (val) {       
       console.log(val);   // 接收父组件的值
      }
    },

https://blog.csdn.net/m0_37852904/article/details/89204244?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-1.channel_param&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-1.channel_param

posted @ 2020-09-30 09:33  ThisCall  阅读(779)  评论(0编辑  收藏  举报