From da259ebec6e14a3e947c29fcf05a2ca69febab1a Mon Sep 17 00:00:00 2001 From: aixianling Date: Tue, 17 May 2022 10:54:34 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=B8=80=E4=B8=8Btab?= =?UTF-8?q?=E9=A1=B5=E7=AD=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/components/mainContent.vue | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/examples/components/mainContent.vue b/examples/components/mainContent.vue index dbc4a2e2..d3b99d95 100644 --- a/examples/components/mainContent.vue +++ b/examples/components/mainContent.vue @@ -21,7 +21,7 @@ export default { ...mapState(['apps']), currentTab() { let {name, query, hash} = this.$route - return [name, query?.id, hash].join("") + return [name?.replace(query?.id, ''), query?.id, hash].join("") } }, data() { @@ -32,21 +32,19 @@ export default { watch: { $route: { immediate: true, - handler(v) { - this.getTabs(v) + handler() { + this.getTabs("route") } }, }, methods: { - handleTabClick(tab) { - let to = {}, selectedTab = this.tabs.find(e => e.name == tab.name) - if (selectedTab) { - to = {...selectedTab, params: {tabclick: 1}} - } else { - let {name, query, hash} = tab - to = {name, query, hash, params: {tabclick: 1}} - } - this.$router.push({...to}) + handleTabClick({name}) { + let {name: route, query, hash} = this.tabs.find(e => e.name == name), + exps = [] + query.id && exps.push(query.id) + hash && exps.push(hash) + let reg = new RegExp(`(${exps.join("|")})`, 'g') + this.$router.push({name: route.replace(reg, ''), query, hash}) }, handleTabRemove(id = this.currentTab) { let tabs = JSON.parse(JSON.stringify(this.tabs)), @@ -57,11 +55,13 @@ export default { } this.tabs.splice(index, 1) }, - getTabs() { + getTabs(from) { let {name, query, hash} = this.$route + console.log(`getTabs>>>>>>>>>%s>>>>>>>%s`, from, name) let tab = this.tabs.find(e => e.name == this.currentTab), tabName = [name, query?.id, hash].join("") if (tab) { + } else if (!name) { } else if (tabName) { let menu = this.apps.find(e => e.name == name) this.tabs.push({name: tabName, query, hash, label: menu?.label}) @@ -69,7 +69,7 @@ export default { }, }, created() { - this.getTabs() + this.getTabs("created") } }