兄弟組件之間通信可通過共同祖輩搭橋,$parent或$root
組件A監(jiān)聽數(shù)據(jù)
this.$parent.$on('foo',msg=>{
console.log(msg)
})
this.$root.$on('foo',msg=>{
console.log(msg)
})
組件B傳遞數(shù)據(jù)
this.$parent.$emit('foo','傳輸數(shù)據(jù)')
this.$root.$emit('foo',傳輸數(shù)據(jù))
兄弟組件之間通信可通過共同祖輩搭橋,$parent或$root
組件A監(jiān)聽數(shù)據(jù)
this.$parent.$on('foo',msg=>{
console.log(msg)
})
this.$root.$on('foo',msg=>{
console.log(msg)
})
組件B傳遞數(shù)據(jù)
this.$parent.$emit('foo','傳輸數(shù)據(jù)')
this.$root.$emit('foo',傳輸數(shù)據(jù))