$emit官方说明:https://cn.vuejs.org/api/component-instance.html#emit
Children.vue
<script setup lang="ts">
const emits = defineEmits(['refreshList'])
const handleCheck = async (value: number) => {
await axios.post('/api/user/check', {checked: value})
emits('refreshList', false) // 语法:emit(event: string, ...args: any[]): void
}
</script>
Parent.vue
<template>
<Children @refreshList="getData">
</template>
<script setup lang="ts">
import { ref } from 'vue'
const loading = ref<boolean>(false)
const getData = async (showLoading: boolean = true) => {
if(showLoading) {
loading.value = true
}
const data = await axios.get('/api/user/list')
if(showLoading) {
loading.value = false
}
}
</script>