完成登录页面
<template> <div> <div class="login-container"> <div style="width: 350px" class="login-box"> <div style="font-weight: bold; font-size: 24px; text-align: center; margin-bottom: 30px">登 录</div> <el-form :model="item"> <el-form-item prop="username"> <el-input v-model="item.username" placeholder="请输入账号"/> </el-form-item> <el-form-item prop="password"> <el-input show-password v-model="item.password" placeholder="请输入密码"/> </el-form-item> <el-form-item prop="role"> <el-select style="width: 100%" v-model="item.role"> <el-option value="管理员" label="管理员"></el-option> <el-option value="学生" label="学生"></el-option> </el-select> </el-form-item> <el-form-item> <el-button type="primary" style="width: 100%" @click="login">登录</el-button> </el-form-item> </el-form> <!-- <div style="margin-top: 30px; text-align: right"> 还没有账号?请<a href="/register">注册</a> </div> --> </div> </div> </div> </template> <script> import axios from 'axios' export default{ name:'LoginPage', data() { return { item:{ username:'', password:'', role:'', }, person:{}, } }, methods:{ async getData(){ var res=await axios.get('http://localhost:9090/user/'+this.item.username) this.person=res.data.data }, login(){ this.getData() if(this.person.password===this.item.password&&this.person.role===this.item.role){ this.$router.push('/home') }else{ alert('用户名或密码错误') } } }, } </script> <style scoped> .login-container { min-height: 100vh; overflow: hidden; display: flex; align-items: center; justify-content: center; background-image: url('../assets/fresh3.png'); background-size: cover; } .login-box { background-color: rgba(255,255,255,.10); box-shadow: 0 0 10px rgba(0,0,0,0.1); padding: 30px; border-radius: 5px; /* //border: 1px solid #ddd; */ } </style>
标签:axios,item,家庭,person,记账,background,role,255 From: https://www.cnblogs.com/daniel350-wang/p/18036174