From 97de86eacb4564aba609fb6f7179a67aa5457fcd Mon Sep 17 00:00:00 2001 From: litao <897262216@qq.com> Date: Thu, 18 Nov 2021 14:35:05 +0800 Subject: [PATCH] =?UTF-8?q?=E8=8E=B7=E5=BE=97=E6=9C=80=E6=96=B0=E8=8F=9C?= =?UTF-8?q?=E5=8D=95=E5=90=8E=E6=9B=B4=E6=96=B0TagsView=E7=BB=84=E4=BB=B6?= =?UTF-8?q?=E7=9A=84localStorage=E7=BC=93=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/layout/components/TagsView/index.vue | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/layout/components/TagsView/index.vue b/src/layout/components/TagsView/index.vue index 8f97c27..91aee28 100644 --- a/src/layout/components/TagsView/index.vue +++ b/src/layout/components/TagsView/index.vue @@ -217,17 +217,27 @@ ]; }); - let routes: RouteItem[] = []; - + let cacheRoutes: RouteItem[] = []; + const simpleRoute = getSimpleRoute(route); try { const routesStr = storage.get(TABS_ROUTES) as string | null | undefined; - routes = routesStr ? JSON.parse(routesStr) : [getSimpleRoute(route)]; + cacheRoutes = routesStr ? JSON.parse(routesStr) : [simpleRoute]; } catch (e) { - routes = [getSimpleRoute(route)]; + cacheRoutes = [simpleRoute]; } + // 将最新的路由信息同步到 localStorage 中 + const routes = router.getRoutes(); + cacheRoutes.forEach((cacheRoute) => { + const route = routes.find((route) => route.path === cacheRoute.path); + if (route) { + cacheRoute.meta = route.meta || cacheRoute.meta; + cacheRoute.name = (route.name || cacheRoute.name) as string; + } + }); + // 初始化标签页 - tabsViewStore.initTabs(routes); + tabsViewStore.initTabs(cacheRoutes); //监听滚动条 function onScroll(e) {