From 82947fe5b610743fe396258489ca770f88baf825 Mon Sep 17 00:00:00 2001 From: lilinyuan <1084668738@qq.com> Date: Tue, 26 Mar 2024 16:28:46 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=B0=83=E6=95=B4tagsView=E6=96=87?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/stores/tagsview.js | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/stores/tagsview.js b/src/stores/tagsview.js index bcd8706..b278540 100644 --- a/src/stores/tagsview.js +++ b/src/stores/tagsview.js @@ -1,20 +1,21 @@ import { defineStore } from "pinia"; import { ref } from "vue"; -import { useRouter } from "vue-router"; +import { useRouter, useRoute } from "vue-router"; export const useTagsView = defineStore('tagsView',()=>{ const router = useRouter() + const route = useRoute() //已显示的标签页list const visitedViews = ref([]) //添加标签页面 - const addVisitedViews = ({path,meta}) => { + const addVisitedViews = ({path,meta,query}) => { if(visitedViews.value.length == 0) { - visitedViews.value.push({path,meta}) + visitedViews.value.push({path,meta,query}) }else { const paths = visitedViews.value.map(item => item.path) if(paths.includes(path) == false) { - visitedViews.value.push({path,meta}) + visitedViews.value.push({path,meta,query}) } } } @@ -32,6 +33,16 @@ export const useTagsView = defineStore('tagsView',()=>{ toLastTagView(visitedViews) } + //删除当前标签页并跳转到指定路由 + const delViewAndGoView = (path) => { + visitedViews.value.forEach((item,index)=>{ + if(item.path == route.path) { + visitedViews.value.splice(index,1) + } + }) + router.push(path) + } + //删除其他标签页 const delOtherVisitedViews = ({path,meta}) => { visitedViews.value = [] @@ -50,5 +61,6 @@ export const useTagsView = defineStore('tagsView',()=>{ addVisitedViews, delVisitedViews, delOtherVisitedViews, + delViewAndGoView } })