From 0417d5a945318f455942dd12c6e8abfc8d0c927f Mon Sep 17 00:00:00 2001 From: Lxy Date: Wed, 1 Jul 2026 23:53:37 +0800 Subject: [PATCH] fix: login page not redirecting after successful login - Replace validate(async callback) with await validate() Promise API - Use window.location.replace('/') for cleaner redirect - Unify form submission via @submit.prevent and native-type submit - Remove duplicate click and keyup.enter handlers --- ruoyi-ui-next/src/views/login.vue | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/ruoyi-ui-next/src/views/login.vue b/ruoyi-ui-next/src/views/login.vue index d3a818a..a977ae8 100644 --- a/ruoyi-ui-next/src/views/login.vue +++ b/ruoyi-ui-next/src/views/login.vue @@ -21,16 +21,15 @@ :prefix-icon="Lock" size="large" show-password - @keyup.enter="handleLogin" /> 登录 @@ -66,20 +65,20 @@ const rules = { const handleLogin = async () => { if (!formRef.value) return - await formRef.value.validate(async (valid) => { - if (valid) { - loading.value = true - try { - await userStore.login(loginForm.username, loginForm.password) - ElMessage.success('登录成功') - router.push('/') - } catch (error: any) { - ElMessage.error(error.message || '登录失败,请检查用户名和密码') - } finally { - loading.value = false - } - } - }) + try { + // 使用 Promise 方式等待校验完成 + await formRef.value.validate() + loading.value = true + await userStore.login(loginForm.username, loginForm.password) + ElMessage.success('登录成功') + // 使用 window.location.replace 确保页面完全刷新并跳转到首页 + window.location.replace('/') + } catch (error: any) { + console.error('Login error:', error) + ElMessage.error(error.message || '登录失败,请检查用户名和密码') + } finally { + loading.value = false + } }