vue实现登录界面

作者:Hi-Sun 时间:2024-05-02 16:53:56 

使用Vue实现简单的用户登录界面,登录成功以后查询账号用户类型进行相应的页面路由跳转,效果如下图所示:

vue实现登录界面

HTML部分:

<div class="loginbody">
? ? <div class="login">
? ? ? <div class="mylogin" align="center">
? ? ? ? <h4>登录</h4>
? ? ? ? <el-form
? ? ? ? ? :model="loginForm"
? ? ? ? ? :rules="loginRules"
? ? ? ? ? ref="loginForm"
? ? ? ? ? label-width="0px"
? ? ? ? >
? ? ? ? ? <el-form-item
? ? ? ? ? ? label=""
? ? ? ? ? ? prop="account"
? ? ? ? ? ? style="margin-top:10px;"
? ? ? ? ? >
? ? ? ? ? ? <el-row>
? ? ? ? ? ? ? <el-col :span='2'>
? ? ? ? ? ? ? ? <span class="el-icon-s-custom"></span>
? ? ? ? ? ? ? </el-col>
? ? ? ? ? ? ? <el-col :span='22'>
? ? ? ? ? ? ? ? <el-input
? ? ? ? ? ? ? ? ? class="inps"
? ? ? ? ? ? ? ? ? placeholder='账号'
? ? ? ? ? ? ? ? ? v-model="loginForm.account">
? ? ? ? ? ? ? ? </el-input>
? ? ? ? ? ? ? </el-col>
? ? ? ? ? ? </el-row>
? ? ? ? ? </el-form-item>
? ? ? ? ? <el-form-item
? ? ? ? ? ? label=""
? ? ? ? ? ? prop="passWord"
? ? ? ? ? >
? ? ? ? ? ? <el-row>
? ? ? ? ? ? ? <el-col :span='2'>
? ? ? ? ? ? ? ? <span class="el-icon-lock"></span>
? ? ? ? ? ? ? </el-col>
? ? ? ? ? ? ? <el-col :span='22'>
? ? ? ? ? ? ? ? <el-input
? ? ? ? ? ? ? ? ? class="inps"
? ? ? ? ? ? ? ? ? type="password"
? ? ? ? ? ? ? ? ? placeholder='密码'
? ? ? ? ? ? ? ? ? v-model="loginForm.passWord"
? ? ? ? ? ? ? ? ></el-input>
? ? ? ? ? ? ? </el-col>
? ? ? ? ? ? </el-row>
? ? ? ? ? </el-form-item>
? ? ? ? ? <el-form-item style="margin-top:55px;">
? ? ? ? ? ? <el-button
? ? ? ? ? ? ? type="primary"
? ? ? ? ? ? ? round
? ? ? ? ? ? ? class="submitBtn"
? ? ? ? ? ? ? @click="submitForm"
? ? ? ? ? ? >登录
? ? ? ? ? ? </el-button>
? ? ? ? ? </el-form-item>
? ? ? ? ? <div class="unlogin">
? ? ? ? ? ? <router-link :to="{ path: '/forgetpwd'}">
? ? ? ? ? ? ? 忘记密码?
? ? ? ? ? ? </router-link>
? ? ? ? ? ? |
? ? ? ? ? ? <router-link :to="{path: '/register'}">
? ? ? ? ? ? ? <a href="register.vue" target="_blank" align="right">注册新账号</a>
? ? ? ? ? ? </router-link>
? ? ? ? ? </div>
? ? ? ? </el-form>
? ? ? </div>
? ? </div>
? </div>

JS部分

?import {mapMutations} from "vuex";
?
? export default {
? ? name: "Login",
? ? data: function () {
? ? ? return {
? ? ? ? loginForm: {
? ? ? ? ? account: '',
? ? ? ? ? passWord: ''
? ? ? ? },
? ? ? ? loginRules: {
? ? ? ? ? account: [
? ? ? ? ? ? {required: true, message: "请输入账号", trigger: "blur"}
? ? ? ? ? ],
? ? ? ? ? passWord: [{required: true, message: "请输入密码", trigger: "blur"}]
? ? ? ? }
? ? ? }
? ? },
? ?
? ? methods: {
? ? ? ...mapMutations(['changeLogin']),
? ? ? submitForm() {
? ? ? ? let self = this;
? ? ? ? const userAccount = this.loginForm.account;
? ? ? ? const userPassword = this.loginForm.passWord;
? ? ? ? const userForm = new FormData();
? ? ? ? userForm.append('userAccount', userAccount);
? ? ? ? userForm.append('userPassword', userPassword);
? ? ? ? this.axios.post('URL1', userForm
? ? ? ? ).then((res) => {
? ? ? ? ? if (res.data == 0) {
? ? ? ? ? ? self.$message({
? ? ? ? ? ? ? type: 'error',
? ? ? ? ? ? ? message: '密码错误,登陆失败!'
? ? ? ? ? ? })
? ? ? ? ? }
? ? ? ? ? //token
? ? ? ? ? self.sessiontoken = res.headers['sessiontoken'];
? ? ? ? ? self.PageToken = Math.random().toString(36).substr(2);
? ? ? ? ? sessionStorage.setItem('PageToken', self.PageToken);
? ? ? ? ? self.changeLogin({sessiontoken: self.sessiontoken});
? ? ? ? ? //登录成功
? ? ? ? ? if (res.data == 1) {
? ? ? ? ? ? self.axios.get("URL2"
? ? ? ? ? ? ).then((res) => {
? ? ? ? ? ? ? if (res.data == null) {
? ? ? ? ? ? ? ? self.$message({
? ? ? ? ? ? ? ? ? type: 'error',
? ? ? ? ? ? ? ? ? message: '查询失败!'
? ? ? ? ? ? ? ? })
? ? ? ? ? ? ? } else {
? ? ? ? ? ? ? ? if (res.data.userType == 0) {
? ? ? ? ? ? ? ? ? self.$router.push({path: '/supermana', replace: true})
? ? ? ? ? ? ? ? } else if (res.data.userType == 1) {
? ? ? ? ? ? ? ? ? self.$router.push({path: '/manauser', replace: true})
? ? ? ? ? ? ? ? } else if (res.data.userType == 2) {
? ? ? ? ? ? ? ? ? self.$router.push({path: '/ordinauser', replace: true})
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? }
? ? ? ? ? ? }).catch((error) => {
? ? ? ? ? ? ? console.log(error)
? ? ? ? ? ? })
? ? ? ? ? }
? ? ? ? })
? ? ? },
? ? }
? }

CSS部分

?.loginbody {
? ? overflow: scroll;
? ? overflow-y: hidden;
? ? overflow-x: hidden;
? }
?
? .login {
? ? width: 100vw;
? ? padding: 0;
? ? margin: 0;
? ? height: 100vh;
? ? font-size: 16px;
? ? background-position: left top;
? ? background-color: #242645;
? ? color: #fff;
? ? font-family: "Source Sans Pro";
? ? position: relative;
? ? background-image: url('/static/images/background.jpg');
? ? background-repeat: no-repeat;
? ? background-size: 100% 100%;
? }
?
? .mylogin {
? ? width: 240px;
? ? height: 280px;
? ? position: absolute;
? ? top: 0;
? ? left: 0;
? ? right: 0;
? ? bottom: 0;
? ? margin: auto;
? ? padding: 50px 40px 40px 40px;
? ? box-shadow: -15px 15px 15px rgba(6, 17, 47, 0.7);
? ? opacity: 1;
? ? background: linear-gradient(
? ? ? 230deg,
? ? ? rgba(53, 57, 74, 0) 0%,
? ? ? rgb(0, 0, 0) 100%
? ? );
? }
?
? .inps input {
? ? border: none;
? ? color: #fff;
? ? background-color: transparent;
? ? font-size: 12px;
? }
?
? .submitBtn {
? ? background-color: transparent;
? ? color: #39f;
? ? width: 200px;
? }

来源:https://blog.csdn.net/Helloyaling/article/details/106794815

标签:vue,登录界面
0
投稿

猜你喜欢

  • Go语言中关闭带缓冲区的频道实例分析

    2024-02-20 07:55:16
  • python支持多继承吗

    2023-10-14 11:22:48
  • 如何通过Python收集MySQL MHA 部署及运行状态信息的功能

    2024-01-13 22:14:44
  • Python 找出出现次数超过数组长度一半的元素实例

    2023-06-07 05:50:33
  • git基础之各版本控制系统介绍

    2022-02-14 02:16:03
  • Python中matplotlib如何改变画图的字体

    2023-02-19 16:46:38
  • python 判断字符串当中是否包含字符(str.contain)

    2022-11-10 04:21:10
  • Python编程django实现同一个ip十分钟内只能注册一次

    2023-01-18 17:01:55
  • 在ubuntu中重置mysql服务器root密码的方法

    2024-01-24 19:40:48
  • django配置app中的静态文件步骤

    2021-03-15 21:43:57
  • python使用openpyxl操作excel的方法步骤

    2022-09-30 20:59:24
  • MySQL Administrator 登录报错的解决方法

    2024-01-21 06:53:06
  • 详解numpy.ndarray.reshape()函数的参数问题

    2022-02-06 20:22:57
  • php通过pecl方式安装扩展的实例讲解

    2023-07-23 07:06:12
  • pyqt5 QListWidget的用法解析

    2023-09-24 21:30:31
  • Anaconda2下实现Python2.7和Python3.5的共存方法

    2022-06-30 12:43:30
  • flask框架jinja2模板与模板继承实例分析

    2023-08-26 22:21:34
  • 简单了解Django ORM常用字段类型及参数配置

    2022-11-03 09:11:38
  • Python数据分析中Groupby用法之通过字典或Series进行分组的实例

    2023-03-08 12:56:01
  • asp产生不重复的随机数

    2008-06-03 13:29:00
  • asp之家 网络编程 m.aspxhome.com