From 442e8bc5cbf8b29c2c5666a44409f15549720cff Mon Sep 17 00:00:00 2001 From: zhaowenkang Date: Fri, 6 Feb 2026 14:56:27 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=BF=E7=94=A8setTimeout=E4=BB=A3=E6=9B=BFn?= =?UTF-8?q?extTick?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/EventManagement/ContentConfiguration.vue | 34 +++++++++++----------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/views/EventManagement/ContentConfiguration.vue b/src/views/EventManagement/ContentConfiguration.vue index b79db73..c95d1d8 100644 --- a/src/views/EventManagement/ContentConfiguration.vue +++ b/src/views/EventManagement/ContentConfiguration.vue @@ -446,10 +446,6 @@ const resetForm = () => { form.probability = null; form.img = ""; fileList.value = []; - // 清除校验红字 - nextTick(() => { - formRef.value?.resetFields(); - }); }; // 添加按钮 @@ -457,6 +453,21 @@ const add = () => { isEdit.value = false; resetForm(); dialogFormVisible.value = true; + // 清除校验红字 + /* nextTick虽然是异步的,但它执行的时机非常“快”(微任务队列)。设置 dialogFormVisible = true 时, 开始渲染。 + 但由于弹窗可能有动画,或者内部组件是懒加载的,在 nextTick 执行的那一瞬间, 可能还没有真正渲染到 DOM 上。 + 此时 formRef.value 是 undefined,所以 clearValidate() 其实根本没有执行成功。*/ + + // nextTick(() => { + // formRef.value?.clearValidate(); + // }); + + //setTimeout 会将任务推到宏任务队列,确保在 DOM 渲染、弹窗打开动画开始之后再执行,保证 formRef 一定存在。 + setTimeout(() => { + if (formRef.value) { + formRef.value.clearValidate(); + } + }, 0); }; const submitForm = async () => { @@ -517,20 +528,9 @@ const deleteDraw = async (row) => { }; const handleEdit = (row) => { - console.log(row); isEdit.value = true; - form.id = undefined; - form.stick_type = ""; - form.prize_type = ""; - form.item_name = ""; - form.templateName = ""; - form.term_value = null; - form.time_unit = 3; - form.num = null; - form.probability = null; - form.img = ""; - fileList.value = []; + resetForm(); form.id = row.id; form.stick_type = row.stick_type; @@ -561,7 +561,7 @@ const handleEdit = (row) => { // 6. 在 DOM 更新后,解除锁并清除校验 nextTick(() => { - isEditMode.value = false; // 解除锁 + isEdit.value = false; // 解除锁 if (formRef.value) { formRef.value.clearValidate(); // 去掉一打开就红一片的校验信息 }