尝试添加login逻辑

This commit is contained in:
高子兴 2024-06-30 15:55:26 +08:00
parent ad1abc8a3d
commit 15dbc6fcd2

View File

@ -1,15 +1,29 @@
<script setup> <script setup>
import { ref } from 'vue'; import { ref } from 'vue';
import { ElInput, ElButton, ElCheckbox, ElForm, ElFormItem } from 'element-plus'; import { ElInput, ElButton, ElCheckbox, ElForm, ElFormItem, ElMessage } from 'element-plus';
import 'element-plus/dist/index.css'; import 'element-plus/dist/index.css';
import axios from 'axios';
const username = ref(''); const username = ref('');
const password = ref(''); const password = ref('');
const rememberMe = ref(false); const rememberMe = ref(false);
const handleLogin = () => { const handleLogin = async () => {
console.log('Logging in with', { username: username.value, password: password.value, rememberMe: rememberMe.value }); console.log('Logging in with', { username: username.value, password: password.value, rememberMe: rememberMe.value });
// try {
const response = await axios.post('/api/login', {
username: username.value,
password: password.value,
});
if (response.data === 'Login successful!') {
ElMessage.success('登录成功');
//
} else {
ElMessage.error('用户名或密码错误');
}
} catch (error) {
ElMessage.error('登录失败,请稍后再试');
}
}; };
</script> </script>