泰国晚娘2,marlaina mah,顺德公安网
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父组件调用子组件事件方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持移动技术网。
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
详解element上传组件before-remove钩子问题解决
vue.js中使用微信扫一扫解决invalid signature问题(完美解决)
网友评论