用vue写一个好看的登录页面
时间: 2023-08-04 07:12:06 浏览: 36
好的,下面是一个简单的用 Vue 编写的登录页面示例:
```html
<template>
<div class="login-container">
<h2>登录</h2>
<form class="login-form">
<div class="form-field">
<label for="username">用户名:</label>
<input type="text" id="username" v-model="username" />
</div>
<div class="form-field">
<label for="password">密码:</label>
<input type="password" id="password" v-model="password" />
</div>
<button class="login-button" @click.prevent="login()">登录</button>
</form>
</div>
</template>
<script>
export default {
data() {
return {
username: "",
password: "",
};
},
methods: {
login() {
// 处理登录逻辑
},
},
};
</script>
<style scoped>
.login-container {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
background-color: #f5f5f5;
}
.login-form {
display: flex;
flex-direction: column;
background-color: white;
padding: 30px;
border-radius: 5px;
box-shadow: 0px 2px 4px rgba(0, 0, 0, 0.1);
}
.form-field {
margin-bottom: 20px;
}
label {
font-weight: bold;
margin-right: 10px;
}
input {
padding: 5px;
border: none;
border-radius: 3px;
box-shadow: 0px 2px 4px rgba(0, 0, 0, 0.1);
}
.login-button {
padding: 10px;
background-color: #007bff;
color: white;
border: none;
border-radius: 3px;
box-shadow: 0px 2px 4px rgba(0, 0, 0, 0.1);
cursor: pointer;
}
.login-button:hover {
background-color: #0069d9;
}
</style>
```
这个登录页面的样式比较简单,主要是通过 flex 来布局,并且使用了一些简单的样式来让页面看起来更美观。在代码中,我们使用了 Vue 的双向数据绑定来实现表单的数据收集,使用了 @click.prevent 来阻止表单的默认提交行为,并且在 login 方法中处理了登录逻辑。