为什么有些是res.data.code有些是res.code
axios请求
async handleLogin() {
this.$refs.loginForm.validate(async (valid) => {
if (valid) {
this.loading = true
let res = await loginApi(this.loginForm)
if (String(res.code) === '1') {
console.log(res.code)
console.log(res.data)
localStorage.setItem('userInfo',JSON.stringify(res.data))
window.location.href= '../../index.html'
} else {
this.$message.error(res.msg)
this.loading = false
}
}
})
}
axios拦截器
service.interceptors.response.use(res => {
if (res.data.code === 0 && res.data.msg === 'NOTLOGIN') {// 返回登录页面
console.log(res.data.data)
console.log(res.data)
localStorage.removeItem('userInfo')
window.top.location.href = '/backend/page/login/login.html'
} else {
return res.data
}
},
error => {