子组件
<template>
<div>
</div>
</template>
<script>
export default {
methods: {
childEvent() {
alert("我是子组件方法");
}
}
};
</script>
父组件
<template>
<div>
<child ref="child"/>
</div>
</template>
<script>
import child from './child';
export default {
components: {
child
},
methods: {
parentEvent() {
this.$refs.child.childEvent();
}
}
};
</script>
这篇博客介绍了Vue.js中父子组件如何进行事件通信。通过示例展示了子组件定义方法`childEvent`,然后在父组件中通过`$refs`调用该方法实现交互。这种通信方式在Vue应用开发中非常常见,有助于理解组件间的协作。
655

被折叠的 条评论
为什么被折叠?



