Template
1
0
mirror of https://github.com/un-pany/v3-admin-vite.git synced 2025-04-21 11:29:20 +08:00

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

View File

@ -8,7 +8,19 @@ export const useTagsViewStore = defineStore("tags-view", () => {
const visitedViews = ref<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))
}
const delVisitedView = (view: ITagView) => {

View File

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