vue 登录直接跳转首页

目录

 

 

目录

one

首先在登录页面longin操作

创建utils.js

main.js中引用

         store中user.js 

two  



one

首先在登录页面longin操作

在if中判断你返回的值是多少

handleLogin() {
this.loading = true
      this.$store
        .dispatch('user/login', this.loginForm)
        .then((res) => {
          //判断您返回的值是什么
          if (res.code != 200) {
            this.$message.error('请输入正确账号密码')
          } else {
            this.$router.replace({ path: this.redirect || '/' })
          }
          this.loading = false
        })
        .catch(() => {
          this.loading = false
        })
}         
  created() {
    let Base64 = require('js-base64').Base64
    let channel = Base64.decode(this.$utils.getUrlKey('verinfo')).split(',')
    if (channel != undefined) {
      ;(this.loginForm.username = channel[0]),
        (this.loginForm.password = channel[1])
      this.handleLogin()
    }
  },

创建utils.js

export default {
    getUrlKey: function (name) {
        return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.href) || [, ""])[1].replace(/\+/g, '%20')) || null;
    }
}
/// 解密
// export function Decrypt(str) {
//     // let encryptedHexStr = CryptoJS.enc.Hex.parse(word);
//     // let srcs = CryptoJS.enc.Base64.stringify(encryptedHexStr);
//     let decrypt = CryptoJS.AES.decrypt(str, key, { iv: iv, mode: CryptoJS.mode.CBC, padding: CryptoJS.pad.Pkcs7 });
//     let decryptedStr = decrypt.toString(CryptoJS.enc.Utf8);
//     return decryptedStr.toString();
// }
// /// 加密
// export function AES_CBC_encrypt(word) {
//     let srcs = CryptoJS.enc.Utf8.parse(word);
//     let encrypted = CryptoJS.AES.encrypt(srcs, key, { iv: iv, mode: CryptoJS.mode.CBC, padding: CryptoJS.pad.Pkcs7 });
//     return encrypted.ciphertext.toString().toUpperCase();
// }

main.js中引用

import utils   from './utils'

Vue.prototype.$utils=utils

store中user.js 

store中user.js 的  const {data} = response  加不加这{}取决于您登陆验证 其次是在  resolve(data) 加上返回的data

如果没有返回token  可以用下面这张写法      

 const  data  = response  下的if判断逻辑根据您的需求来写   例如:

      if(data.data){
          commit('SET_TOKEN', data.token)
          setToken(data.token)
        }

或者 

http://链接地址ip:端口/#/login?verinfo=base64加密后的账号,密码

base64加密后的账号,密码为:[账号,密码]   账号和密码中间用,【逗号】隔开

例如:YWRtaW4sMTIzMTIz   是  admin,123123          base64加密后的账号,密码则为         YWRtaW4sMTIzMTIz

two  

handleLogin() {
      // this.$refs.loginForm.validate((valid) => {
      //   if (valid) {
      //     this.loading = true;
      //     this.$store
      //       .dispatch("user/login", this.loginForm)
      //       .then((res) => {
      //         if (res.code != 200) {
      //           this.$message.error("请输入正确账号密码");
      //         } else {
      //           this.$router.replace({ path: this.redirect || "/" });
      //         }
      //         this.loading = false;
      //       })
      //       .catch(() => {
      //         this.loading = false;
      //       });
      //   } else {
      //     // console.log('error submit!!')
      //     return false;
      //   }
      // });

         this.loading = true
      this.$store
        .dispatch('user/login', this.loginForm)
        .then((res) => {
          if (res.code != 200) {
            this.$message.error('请输入正确账号密码')
          } else {
            this.$router.replace({ path: this.redirect || '/' })
          }
          this.loading = false
        })
        .catch(() => {
          this.loading = false
        })
    },

 

  created() {
    let channel = decodeURIComponent(
      (new RegExp("[?|&]" + "verinfo" + "=" + "([^&;]+?)(&|#|;|$)").exec(
        location.href
      ) || [, ""])[1].replace(/\+/g, "%20")
    ).split(",");
    if (channel != undefined && channel.length > 1) {
      (this.loginForm.username = channel[0]),
        (this.loginForm.password = channel[1]);
      console.log(this.loginForm.username);
      console.log(this.loginForm.password);
      this.handleLogin();
    }
  },

http://链接地址ip:端口/#/login?verinfo=账号,密码

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  • 1
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值