其他分享
首页 > 其他分享> > vue2 登录页面 跳转 包括token部分 $router部分

vue2 登录页面 跳转 包括token部分 $router部分

作者:互联网

js文件内

import request from "@/utils/request";

export function login(data) {
  return request({
    url: "/auth/login",
    method: "post",
    data,
  });
}

登录 vue

<template>
  <div class="login-page page">
    <div class="login-form">
      <div class="title"></div>
      <div class="login-box">
        <div class="form-title">密码登录</div>
        <a-form class="form" :model="formState">
          <a-form-item name="username" class="form-input">
            <img src="../assets/login/icon-user.png" />
            <a-input v-model="formState.username" placeholder="请输入用户名" />
          </a-form-item>
          <a-form-item name="password" class="form-input">
            <img src="../assets/login/icon-password.png" />
            <a-input-password
              v-model="formState.password"
              placeholder="请输入密码"
            />
          </a-form-item>
        </a-form>
        <div
          class="btn-login"
          role="button"
          @click="onLogin"
          @keyup.enter="onLogin"
        >
          登录
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { login } from "@/api/auth";
export default {
  data() {
    return {
      formState: {
        username: "",
        password: "",
      },
    };
  },
  methods: {
    async onLogin() {
      const res = await login({
        username: this.formState.username,
        password: this.formState.password,
      });
      console.log(res);
      const { token } = res;
      // localStorage.setItem("token", token);
      localStorage.removeItem("token", token);
      this.$router.push("/home/site-management");
    },
  },
};
</script>

<style lang="less" scoped>
.login-page {
  // width: 1920px;
  // height: 1080px;
  background: url("../assets/login/login.png") no-repeat;
  padding-top: 282px;
  // background-attachment: fixed;
  background-size: 100% 100%;
  .login-form {
    margin: 0 auto;
    width: 521px;
  }
  .title {
    width: 521px;
    height: 46px;
    background: url("../assets/login/login-title.png");
  }
  .login-box {
    margin-top: 43px;
    width: 520px;
    height: 491px;
    background: linear-gradient(153deg, #125898 0%, #172447 20%, #171c47 100%);
    box-shadow: inset 0px 0px 60px 0px rgba(0, 240, 255, 0.1);
    opacity: 1;
    border: 2px solid;
    border-image: linear-gradient(
        90deg,
        rgba(122, 210, 255, 0),
        rgba(122, 210, 255, 1),
        rgba(122, 210, 255, 0)
      )
      2 2;
    .form-title {
      width: 400px;
      padding-bottom: 15px;
      border-bottom: 1px solid rgba(238, 238, 238, 0.2);
      font-size: 24px;
      font-family: PingFang SC-Medium, PingFang SC;
      font-weight: 500;
      color: #ffffff;
      line-height: 28px;
      text-align: center;
      margin: 41px auto 0;
    }
    .form {
      margin: 48px auto;
      width: 400px;
      .form-input {
        margin-bottom: 32px;
        width: 400px;
        height: 60px;
        background: rgba(255, 255, 255, 0.1);
        border-radius: 4px 4px 4px 4px;
        border: 1px solid rgba(255, 255, 255, 0.31);
        position: relative;
        img {
          position: absolute;
          top: 18px;
          left: 12px;
        }
      }
    }
    .btn-login {
      margin: 0 auto;
      text-align: center;
      width: 400px;
      line-height: 60px;
      background: #0077e4;
      border-radius: 2px 2px 2px 2px;
      font-size: 20px;
      font-family: PingFang SC-Semibold, PingFang SC;
      font-weight: 600;
      color: #ffffff;
      cursor: pointer;
    }
  }
}
::v-deep {
  .ant-col {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    .ant-input,
    .ant-input-password {
      position: absolute;
      top: 0;
      left: 0;
      height: 58px;
      border: 0;
      padding-left: 48px;
      color: #fff;
      background-color: transparent;
      width: 397px;
      outline: none;
    }
    .ant-input:focus,
    .ant-input-password:focus {
      outline: none;
    }
  }
}
</style>


关于token 参考这个网页

https://blog.csdn.net/m0_46979453/article/details/124221022

关于-localStorage.setItem与localStorage.removeItem 参考这个网页

https://blog.csdn.net/zx960103/article/details/119180198

标签:background,rgba,width,token,vue2,跳转,login,255
来源: https://www.cnblogs.com/zongkm/p/16662585.html