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.

63 lines
1.4 KiB
Vue

This file contains ambiguous Unicode characters!

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: 400px;
margin: 100px auto;
text-align: center;
}
input {
display: block;
margin: 10px auto;
padding: 8px;
width: 80%;
}
button {
padding: 10px 20px;
}
</style>