Vue 關於多個父子組件嵌套傳值


prop 是單向綁定的:當父組件的屬性變化時,將傳導給子組件,但是不會反過來。這是為了防止子組件無意修改了父組件的狀態——這會讓應用的數據流難以理解。

props: {  
selectMember: {
      type: Boolean,
      default: false 
   }

 

在子組件內的data對象中創建一個props屬性的副本

data:(){
  return{
 seleectPersonMetting:this.selectMember
   }
}

 

創建針對props屬性的watch來同步組件外對props的修改

此時父組件修改了組件的props,會同步到子組件內對應的props上,但是不會同步到你剛剛在data對象中創建的那個副本上,所以需要再創建一個針對props屬性result的watch,做事件派發$emit,當props修改后對應data中的副本myResult也要同步數據。

watch:{
selectMember(val){
       this.seleectPersonMetting=val
    },
    seleectPersonMetting(val) {
      this.$emit('select-mode', val);
    }
}

在父組件上接收子組件watch過來的事件

接收子組件傳遞過來的自定義事件

 <Right @select-mode='selectMde'></Right>


method:{
    selectMde(val){
        this.selectMeetingMemberMode = val
     },

}

 

 selectMember: {
      type: Boolean,
      default: false


免責聲明!

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



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