vue登录及问题

vue登录及问题

不包含登录拦截单纯的登录
html:

<div class="logincontent">
              <div class="fromlogin">
                <div class="login-item username">
                  <input type="text" placeholder="账   号" v-model="name">
                </div>
                <div class="login-item password">
                  <input type="password" placeholder="密   码" v-model="pwd">
                </div>
                <mt-button style="margin-top:25px;" class="loginBtn" @click="login" type="primary">登录</mt-button>
              </div>
            </div>

js:

 login () {
      if(this.name=='' || this.pwd==''){
       this.$message.error('账号密码不能为空!');
      }else{
       this.$axios.post('/api/preach/account/login',qs.stringify({
         username : this.name,
         password : this.pwd
       })).then((res)=>{
         if (res.data) {
                   this.$router.push({
                     path: '/my',
                 });
                   sessionStorage.setItem('name',res.data.group.name);
                   sessionStorage.setItem('id',res.data.group.parentId);
                   sessionStorage.setItem('groupId',res.data.group.id);
                   sessionStorage.setItem('parentId',res.data.group.parentId);
                   sessionStorage.setItem('code',res.data.roles[0].code);
                    
         } else {
          this.$message.error('账号或密码错误!');
         }
                }).catch(err => {
                  this.$message.error('请稍后再试');//  登录失败提示
                })
                //.then是指接口能正常访问,但是访问也得看账号密码对不对,所以判断是写在这个里面,判断也是根据接口返回去判断
                //在这个接口里面,后台的意思是如果账号密码正确会给你返回data(res.data)如果不正确就不会给返回
                //.catch是指接口不能访问的时候,比如网络不行或者是后台服务挂了,服务根本就不能用
      }
      
    }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值