You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
<!--
* @ Descripttion :
* @ version : 1.0 .0
* @ Author : LyMy
* @ Date : 2025 - 04 - 11 15 : 46 : 41
* @ LastEditors : LyMy
* @ LastEditTime : 2025 - 04 - 11 16 : 23 : 46
* @ FilePath : \ fish _game \ src \ pages \ login \ Login . vue
-- >
< template >
< div class = "login-page" >
< h1 > 登录 < / h1 >
< form @submit.prevent ="handleLogin" >
< input v-model ="Name" placeholder="用户名" />
<input v-model="Password" type="password" placeholder="密码" />
<button type="submit" > 登 录 < / button >
< / form >
< / div >
< / template >
< script setup >
import { ref } from 'vue'
import { login } from '@/api/login/login'
import { useRouter } from 'vue-router'
const router = useRouter ( )
const Name = ref ( '' )
const Password = ref ( '' )
async function handleLogin ( ) {
try {
const res = await login ( { Name : Name . value , Password : Password . value } )
if ( res && res . token ) {
localStorage . setItem ( 'token' , res . token )
router . push ( '/' )
} else {
alert ( '登录失败, 未返回token' )
}
} catch ( err ) {
alert ( '登录失败,请检查网络或重试' )
console . error ( '登录错误:' , err )
}
}
< / script >
< style scoped >
. login - page {
max - width : 400 px ;
margin : 100 px auto ;
text - align : center ;
}
input {
display : block ;
margin : 10 px auto ;
padding : 8 px ;
width : 80 % ;
}
button {
padding : 10 px 20 px ;
}
< / style >