Vue父组件调用子组件事件方法
更新时间:2018年02月23日 11:09:05 作者:小鹅鹅
下面小编就为大家分享一篇Vue父组件调用子组件事件方法,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
Vue父组件向子组件传递事件/调用事件
不是传递数据(props)哦,适用于 Vue 2.0
方法一:子组件监听父组件发送的方法
方法二:父组件调用子组件方法
子组件:
export default { mounted: function () { this.$nextTick(function () { this.$on('childMethod', function () { console.log('监听成功') }) }) }, methods { callMethod () { console.log('调用成功') } } }
父组件:
<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父组件调用子组件事件方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持脚本之家。
相关文章
vue router总结 $router和$route及router与 router与route区别
这篇文章主要介绍了vue router总结 $router和$route及router与 router与route区别,本文给大家介绍的非常详细,具有一定的参考借鉴价值 ,需要的朋友可以参考下2019-07-07解决Vue警告Write operation failed:computed value is readonl
这篇文章主要给大家介绍了关于如何解决Vue警告Write operation failed:computed value is readonly的相关资料,文中通过实例代码介绍的非常详细,需要的朋友可以参考下2023-03-03
最新评论