父组件
<template>
<div>我是父组件</div>
<children @handleEmit="onmyclick"/>
</template>
<script setup>
import children './components/children.vue';
const onmyclick = () => {
console.log("我被子组件触发了");
}
</script>
子组件
<template>
<div>我是子组件</div>
<button @click="emitclick">点我触发</button>
</template>
<script setup>
import { defineEmit } from 'vue'
// 定义事件
const emit = defineEmit(['handleEmit']);
const emitclick = () => {
emit('handleEmit');
}
</script>