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是指接口不能访问的时候,比如网络不行或者是后台服务挂了,服务根本就不能用
}
}