用VUE做一个登录页面
时间: 2023-10-12 12:17:08 浏览: 28
好的,以下是一个简单的登录页面的示例代码:
```
<template>
<div class="login-form">
<h2>Login</h2>
<form>
<div class="form-group">
<label for="username">Username:</label>
<input type="text" id="username" v-model="username" required>
</div>
<div class="form-group">
<label for="password">Password:</label>
<input type="password" id="password" v-model="password" required>
</div>
<button type="submit" class="btn btn-primary" @click.prevent="login">Login</button>
</form>
</div>
</template>
<script>
export default {
data() {
return {
username: '',
password: ''
}
},
methods: {
login() {
// 处理登录逻辑
console.log('Username:', this.username);
console.log('Password:', this.password);
}
}
}
</script>
<style>
.login-form {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
height: 100vh;
}
form {
display: flex;
flex-direction: column;
align-items: center;
width: 300px;
margin-top: 20px;
}
.form-group {
display: flex;
flex-direction: column;
margin-bottom: 10px;
}
label {
font-weight: bold;
margin-bottom: 5px;
}
input {
padding: 10px;
border-radius: 5px;
border: 1px solid #ccc;
}
button {
margin-top: 20px;
padding: 10px 20px;
border-radius: 5px;
border: none;
background-color: #007bff;
color: #fff;
cursor: pointer;
}
</style>
```
这个登录页面使用了 VUE 的单文件组件结构,包含了一个表单和一个按钮,用户输入用户名和密码后点击按钮即可触发登录函数。在这个示例中,登录函数只是简单地将用户名和密码输出到控制台,你可以根据自己的需求将其替换为真正的登录逻辑。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![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)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)