写一个vue的登录页面
时间: 2023-08-04 22:25:45 浏览: 28
好的,我可以给您提供一个简单的 Vue 登录页面示例:
```html
<template>
<div class="login-container">
<form class="login-form" @submit.prevent="login">
<h2 class="login-title">登录</h2>
<div class="form-group">
<label for="username">用户名:</label>
<input type="text" id="username" v-model="username" required>
</div>
<div class="form-group">
<label for="password">密码:</label>
<input type="password" id="password" v-model="password" required>
</div>
<button type="submit" class="submit-btn">登录</button>
</form>
</div>
</template>
<script>
export default {
data() {
return {
username: '',
password: ''
}
},
methods: {
login() {
// 处理登录逻辑,比如调用接口验证用户名密码
// 如果验证通过,则跳转到首页
this.$router.push('/home')
}
}
}
</script>
<style scoped>
.login-container {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
.login-form {
width: 400px;
padding: 40px;
border: 1px solid #eee;
border-radius: 4px;
}
.login-title {
text-align: center;
margin-bottom: 20px;
}
.form-group {
margin-bottom: 20px;
}
label {
display: inline-block;
width: 80px;
font-weight: bold;
}
input[type="text"],
input[type="password"] {
display: block;
width: 100%;
padding: 6px 12px;
font-size: 14px;
line-height: 1.42857143;
color: #555;
background-color: #fff;
background-image: none;
border: 1px solid #ccc;
border-radius: 4px;
}
.submit-btn {
display: block;
width: 100%;
margin-top: 20px;
padding: 10px;
border: none;
border-radius: 4px;
background-color: #007bff;
color: #fff;
font-size: 16px;
cursor: pointer;
}
.submit-btn:hover {
background-color: #0069d9;
}
</style>
```
这个登录页面包含一个表单,包括用户名和密码两个输入框和一个提交按钮。在提交表单时,会调用 `login` 方法来处理登录逻辑。如果验证通过,则使用 `this.$router.push` 方法跳转到首页。注意这里使用了 Vue Router,需要在组件的 `script` 标签中导入并使用。