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父組件調用子組件事件方法就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持武林網。
新聞熱點
疑難解答