vue3 子组件调用父组件方法 电脑版发表于:2023/9/20 15:28 [TOC] ### 带有setup()的组合API - context.emit ``` 父组件组件 <my-childe ref="RefChilde" @closePopup="closeClassRankingPopup"></my-childe> 子组件组件 setup(props, context) { function handleClose() { context.emit('closeClassRankingPopup', 参数); } } ``` ### 在 `<script setup>` 中的用法 子组件: ``` <template> <view class="container"> <view @click="handleClose">关闭</view> </view> </template> const emitWays = defineEmits(['closePopup']) const handleClose = () => { emitWays('closePopup','参数') } ``` 父组件: ``` <uni-popup ref="classRankingPopup" type="bottom" @change="change"> <classSort :classRankData="state.classRankData" @closePopup="closeClassRankingPopup"></classSort> </uni-popup> ```