0
点赞
收藏
分享

微信扫一扫

OA系统登录界面(比较好看)

萨摩斯加士奇 2023-07-14 阅读 65
  1. 子组件触发父组件事件

子组件代码 :

// ChildComponent.vue
<template>
  <button @click="emitEvent">Click me</button>
</template>

<script setup>
import { ref } from 'vue';

const emitEvent = () => {
  emit('childEvent');
};

const emit = defineEmits(['childEvent']);
</script>

父组件代码:

// ParentComponent.vue
<template>
  <ChildComponent @childEvent="handleEvent" />
</template>

<script setup>
import { ref } from 'vue';
import ChildComponent from './ChildComponent.vue';

const handleEvent = () => {
  console.log('Child event triggered');
};
</script>
举报

相关推荐

0 条评论