图示:
父子传参
子组件
Child.vue
<template>
<div>
<button @click="childEmit">父组件传参</button>
</div>
</template>
<script>
export default {
setup(props,{
emit}){
function childEmit () {
emit('my-emit', '我是子组件值')
}
return{
childEmit
}
}
};
</script>
父组件
father.vue
<template>
<div>
<child @my-emit="parentEmit"></child>
</div>
</template>
<script>
import Child from "./Child.vue";
import {
ref } from "vue"