Vue的$emit和$on

created(){
  // $on第一个参数可为数组 this.$on(['myEvents1','myEvents2'],this.handleEvent)
  // 也可以为同一个on事件绑定两个处理事件
  // this.$on('myEvents',this.handleEvent1)
  // this.$on('myEvents',this.handleEvent2)
  this.$on('myEvents',this.handleEvent)
},
methods:{
  handleClick(){
    this.$emit('myEvents','my params')
  },
  handleEvent(){

  }
}

  

猜你喜欢

转载自www.cnblogs.com/whalegood/p/12819473.html