用vue帮我写一个登录页面
时间: 2023-08-28 15:40:22 浏览: 39
好的,以下是一个简单的登录页面示例:
```html
<template>
<div class="login-container">
<h1>登录</h1>
<form @submit.prevent="handleLogin">
<label for="username">用户名</label>
<input type="text" id="username" v-model="username" required>
<label for="password">密码</label>
<input type="password" id="password" v-model="password" required>
<button type="submit">登录</button>
</form>
</div>
</template>
<script>
export default {
data() {
return {
username: '',
password: ''
}
},
methods: {
handleLogin() {
// 在这里处理登录逻辑
console.log('用户名:', this.username)
console.log('密码:', this.password)
// 可以通过axios等工具发送请求到后端进行验证
}
}
}
</script>
<style>
.login-container {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100vh;
background-color: #f2f2f2;
}
form {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
width: 300px;
margin-top: 20px;
padding: 20px;
background-color: #fff;
border-radius: 5px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
}
label {
font-size: 16px;
margin-bottom: 5px;
}
input {
width: 100%;
padding: 10px;
margin-bottom: 10px;
border: 1px solid #ccc;
border-radius: 5px;
font-size: 16px;
}
button[type="submit"] {
width: 100%;
padding: 10px;
margin-top: 20px;
background-color: #007bff;
color: #fff;
border: none;
border-radius: 5px;
font-size: 16px;
cursor: pointer;
}
button[type="submit"]:hover {
background-color: #0069d9;
}
</style>
```
你可以将这段代码复制到.vue文件中进行调试。注意,这只是一个简单的示例,实际开发中需要根据具体需求进行优化和改进。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)