好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

基于vue 兄弟组件之间事件触发(详解)

直奔主题!

兄弟组件之间的事件触发,大概思 android 路是通过父级组件交换数据,watch来监听触发事件。

场景是父级组件A同时引用两个子级组件B,C。点击B组件中的按钮执行C组件中的事件。

第一步:父级组件A

<bottom-play :play="playStatus" @playStatus="btmChild"></bottom-play> 
   
 m http://HdhCmsTestcppcns测试数据 ethods:{ 
 listChild:function(val){//B组件自定义事件 状态是布尔值 
  this.playStatus = val; 
  }, 
 btmChild:function(val){//C组件自定义事件 
      php  this.btmStatus = val; 
  } 
} 

第二步:子级组件B代码

props: ['play'],//接受父级传递的数据 
watch:{//监听数据 如果改变执行audioPlay函数,audioPlay在methods中定义 
  play:'audioPlay' 
} 
audioPlay:function(){ 
 this.$emit('playStatus',false);//向父级组件传递参数 
} 

第三步:子级组件C代码

props: ['btmStatus'] 
,watch:{ 
  btmStatus:'playList' 
} 

总结就是A组件定义两个值分别传递给B,C。然后B,C组件watch方法监听数据触发事件。

以上这篇基于 vue 兄弟组件之间事件触发(详解)就是 python 小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多http://HdhCmsTestcppcns测试数据支持我们。

查看更多关于基于vue 兄弟组件之间事件触发(详解)的详细内容...

  阅读:25次