和 Vue2 子传父案例简单入门 相比,Vue 3 子传父的 emit 使用略有不同,同样 通过 Father.vue 和 Child.vue 展示
首先是 Child.vue,重点在 setup 函数中引入 context 形参,配合 emit 使用。定义了两个函数,toFatherNum(), toFatherObject() 分别向父组件传递数字和对象
<template>
<a-button @click="toFatherNum">子传父数字</a-button>
<a-button @click="toFatherObject">子传父对象</a-button>
</template>
<script lang="ts">
import {
defineComponent } from '