父子路由傳參


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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM