Vuejs中父组件主动调用子组件的方法

转自:https://www.jianshu.com/p/d6e2611df0b6

 

1.首先在子组件中进行事件广播

 

created: function(){
    this.$on('handleChange', function(){
      console.log('something handled!');
    });
  }

2. 在父组件中指定子组件的ref,如child,然后通过以下方式调用:

this.$refs['child'].$emit('handleChange');

 

posted @ 2020-05-29 11:27  一团小源源  阅读(109)  评论(0)    收藏  举报