有一个需求:
后端返回数据表示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') }