@ -21,16 +21,15 @@
: prefix - icon = "Lock"
size = "large"
show - password
@ keyup . enter = "handleLogin"
/ >
< / e l - f o r m - i t e m >
< el -form -item >
< el -button
type = "primary"
native - type = "submit"
size = "large"
style = "width: 100%"
: loading = "loading"
@ click = "handleLogin"
>
登录
< / e l - b u t t o n >
@ -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 {
/ / 使 用 P r o m i s e 方 式 等 待 校 验 完 成
await formRef . value . validate ( )
loading . value = true
await userStore . login ( loginForm . username , loginForm . password )
ElMessage . success ( '登录成功' )
/ / 使 用 w i n d o w . l o c a t i o n . r e p l a c e 确 保 页 面 完 全 刷 新 并 跳 转 到 首 页
window . location . replace ( '/' )
} catch ( error : any ) {
console . error ( 'Login error:' , error )
ElMessage . error ( error . message || '登录失败,请检查用户名和密码' )
} finally {
loading . value = false
}
}
< / script >