2022-08-29 在点击登录的时候再次表单验证
login(formName) {
// 在点击前再次进行表单验证,不通过是不会提交信息给服务器端的
this.$refs.loginForm.validate((valid) => {
if(!valid) return
alert("登录")
}
)
},
这是elementui中表单的一个方法
点击登录后的回调函数以及跳转操作
主要步骤:axios的post提交,判断status值,成功就存储令牌,并使用编程式导航跳转
await this.$http
.post('login',this.loginForm)
.then(res=>{
//the callback of the succuss of login
// console.log(res);
if(res.data.meta.status !== 200) {
//console.log(res.meta.status);it's wrong
return this.$message.error('Fail to login!');
}
this.$message.success('Welcome back!');
// the opreation after seccessful login
window.sessionStorage.setItem('token',res.data.data.token);
// 编程式导航
this.$router.push("/home");
})
.catch(err=>{
console.log(err);
})
如何设置哈希导航?(#/login)
vue的路由有两种模式
https://zhuanlan.zhihu.com/p/550280212

浙公网安备 33010602011771号