有一个需求:
后端返回数据表示token过期,前端要跳到登录页。
if(response.data.message === 'token内容不符'){
Toast({
icon:'fail',
message: '请重新登录',
duration: 1000,
forbidClick: true
});
this.$router.push('/login')
}
提示了一句“Cannot read property '$router' of undefined”
解决方法:
import router from '@/router'; 引入router
if(response.data.message === 'token内容不符'){
Toast({
icon:'fail',
message: '请重新登录',
duration: 1000,
forbidClick: true
});
router.push('/login')
}
博客围绕后端返回token过期,前端跳转登录页时出现‘Cannot read property '$router' of undefined’报错展开,重点在于解决该报错问题,属于前端开发中常见的交互与报错处理场景。
1万+

被折叠的 条评论
为什么被折叠?



