fix: 修复通过 TagsView 刷新页面导致 query 参数丢失的问题

This commit is contained in:
pany 2022-08-26 19:16:49 +08:00
parent 1c568c4817
commit 160858d6de
3 changed files with 21 additions and 6 deletions

View File

@ -68,7 +68,7 @@ const addTags = () => {
} }
const refreshSelectedTag = (view: ITagView) => { const refreshSelectedTag = (view: ITagView) => {
router.replace({ path: "/redirect" + view.fullPath }) router.replace({ path: "/redirect" + view.path, query: view.query })
} }
const closeSelectedTag = (view: ITagView) => { const closeSelectedTag = (view: ITagView) => {
@ -133,9 +133,12 @@ const closeMenu = () => {
} }
watch( watch(
() => route.name, route,
() => { () => {
addTags() addTags()
},
{
deep: true
} }
) )

View File

@ -8,7 +8,19 @@ export const useTagsViewStore = defineStore("tags-view", () => {
const visitedViews = ref<ITagView[]>([]) const visitedViews = ref<ITagView[]>([])
const addVisitedView = (view: ITagView) => { const addVisitedView = (view: ITagView) => {
if (visitedViews.value.some((v) => v.path === view.path)) return if (
visitedViews.value.some((v, index) => {
if (v.path === view.path) {
if (v.fullPath !== view.fullPath) {
// 防止 query 参数丢失
visitedViews.value[index] = Object.assign({}, view)
}
return true
}
})
) {
return
}
visitedViews.value.push(Object.assign({}, view)) visitedViews.value.push(Object.assign({}, view))
} }
const delVisitedView = (view: ITagView) => { const delVisitedView = (view: ITagView) => {

View File

@ -1,10 +1,10 @@
<script lang="ts" setup> <script lang="ts" setup>
import { useRoute, useRouter } from "vue-router" import { useRoute, useRouter } from "vue-router"
const { params, query } = useRoute() const route = useRoute()
const { path } = params const router = useRouter()
useRouter().replace({ path: "/" + path, query }) router.replace({ path: "/" + route.params.path, query: route.query })
</script> </script>
<template> <template>