From 572f53d1d4692ee42db89b819bb6a9fdd7cbc625 Mon Sep 17 00:00:00 2001 From: chenjianxing Date: Wed, 3 Jun 2020 11:07:13 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3localStorage=E6=B8=85?= =?UTF-8?q?=E7=A9=BA=EF=BC=8Ccookie=E6=B2=A1=E5=A4=B1=E6=95=88=E5=AF=BC?= =?UTF-8?q?=E8=87=B4=E7=9A=84=E5=8D=A1=E6=AD=BB=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/common/head/HeaderUser.vue | 1 + .../business/components/common/router/router.js | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/frontend/src/business/components/common/head/HeaderUser.vue b/frontend/src/business/components/common/head/HeaderUser.vue index 6ec894f292..da6e482f5e 100644 --- a/frontend/src/business/components/common/head/HeaderUser.vue +++ b/frontend/src/business/components/common/head/HeaderUser.vue @@ -31,6 +31,7 @@ break; case "logout": this.$get("/signout", function () { + alert("signout"); localStorage.clear(); window.location.href = "/login"; }); diff --git a/frontend/src/business/components/common/router/router.js b/frontend/src/business/components/common/router/router.js index 9aba096521..1326953135 100644 --- a/frontend/src/business/components/common/router/router.js +++ b/frontend/src/business/components/common/router/router.js @@ -31,6 +31,7 @@ import TestPlanView from "../../track/plan/view/TestPlanView"; import TestCase from "../../track/case/TestCase"; import TestTrack from "../../track/TestTrack"; import ApiReportList from "../../api/report/ApiReportList"; +import axios from "axios"; Vue.use(VueRouter); @@ -244,4 +245,18 @@ const router = new VueRouter({ ] }); + +router.beforeEach((to, from, next) => { + //解决localStorage清空,cookie没失效导致的卡死问题 + if (!localStorage.getItem('Admin-Token')) { + axios.get("/signout"); + console.log("signout"); + localStorage.setItem('Admin-Token', "{}"); + window.location.href = "/login"; + next(); + } else { + next(); + } +}); + export default router