callback回调函数的使用
二、例子收拾
/**
回调方法
*/
async function submitForm(
callback: (data: Record<string, string>[], callback: () => void) => void
) {
loading.value = true
callback(formData, () => {
loading.value = false
})
}
/**
方法暴露
*/
defineExpose({
submitForm
})
/**
父组件主动获取调用回调方法
*/
function save() {
selfAssessmentFormRef.value?.submitForm(
(formData: Record<string, string | number>[], callback: () => void) => {
if (formData && formData.length) {
saveData({ data: formData }).then((res) => {
callback && callback()
if (res.code === 200) {
proxy.$message.success('保存成功!')
}
})
}
}
)
}
标签:submitForm,函数,formData,value,callback,回调,void
From: https://blog.csdn.net/weixin_46689373/article/details/137289069