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父组件调用子组件事件方法的全部内容,更多相关Vue父组件调用子组件事件方法内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复