vue父组件调用子组件的方法

时间:2026-02-16 08:02:49

1、下面小编就为大家分享一篇Vue父组件调用子组件事件方法,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧。

vue父组件调用子组件的方法

2、Vue父组件向子组件传递事件/调用事件

不是传递数据(props)哦,适用于 Vue 2.0。

vue父组件调用子组件的方法

3、方法一:子组件监听父组件发送的方法

方法二:父组件调用子组件方法

vue父组件调用子组件的方法

4、子组件:

export default {

  mounted: function () {

   this.$nextTick(function () {

    this.$on('childMethod', function () {

     console.log('监听成功')

    })

   })

  },

  methods {

    callMethod () {

     console.log('调用成功')

    }

  }

}

vue父组件调用子组件的方法

5、父组件:

<child ref="child" @click="click"></child>

export default {

  methods: {

   click () {

   this.$refs.child.$emit('childMethod') // 方法1

   this.$refs.child.callMethod() // 方法2

  },

  components: {

   child: child

  }

}

vue父组件调用子组件的方法

© 2026 阿力知识库
信息来自网络 所有数据仅供参考
有疑问请联系站长 site.kefu@gmail.com