一、父组件:
<template>
<SonModal @cardClick="clickTo"/>
</template>
<script setup>
const clickTo = (e) => {
console.log("e",e);
};
</script>
二、子组件:
<template>
<button @click="sendData">点击按钮</button>
</template>
<script setup>
import { defineEmits } from 'vue'
const sendData = () => {
const data = '这是从子组件传递到父组件的数据'
emits('cardClick', data) // 触发名为 cardClick 的自定义事件,并传递数据
}
const emits = defineEmits(['customEvent'])
</script>
二、子组件(简写)
<template>
<button @click="$emit('cardClick', item)">点击按钮</button>
</template>