下面是express的登录里的代码:就是成功返回“登录成功”里的内容,失败就是catch里的。
exports.login=async (req,res,next)=>{
try {
const user=req.user
const token=await jwt.sign({
userId:user._id
},jwtSecret,{
expiresIn:30000
})
delete user.password
res.status(200).json({
'code':0,
"data":user,
"token":token,
"msg":"登录成功"
})
}catch (err){
next(err)
}
}
下面是vue里调接口的代码:
function handleLogin() {
loginFormRef.value.validate((valid: boolean) => {
if (valid) {
state.loading = true;
user.login(state.loginForm).then((res) => {
console.log("成功")
router.push({ path: state.redirect || '/', query: state.otherQuery });
state.loading = false;
}).catch(() => {
console.log("失败")
state.loading = false;
//handleCaptchaGenerate();
});
} else {
return false;
}
});
}
情况是接口返回信息了,也就是成功了,但是确是从catch里返回的,总提示失败。
发现问题了,我的请求拦截还没修改。。。。哎。。。