Vue3 defineEmit触发事件使用总结
- 前端
- 三生万物
- 0
$emit官方说明:https://cn.vuejs.org/api/component-instance.html#emit
Children.vue
<script setup>
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>
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>
免责申明:本站发布的内容(图片、视频和文字)以转载和分享为主,文章观点不代表本站立场,如涉及侵权请联系站长邮箱:xbc-online@qq.com进行反馈,一经查实,将立刻删除涉嫌侵权内容。