情況一: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