From 2a1921fdbc31152fa880e6f1915dd2dca15620f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E6=B4=AA=E6=B4=AA?= <2498601771@qq.com> Date: Wed, 7 Dec 2022 09:40:21 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8DChartTabs=E7=BB=84?= =?UTF-8?q?=E4=BB=B6=E5=88=9D=E5=A7=8B=E5=8C=96=E6=97=B6activeBar=E5=BC=82?= =?UTF-8?q?=E4=BD=8D=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/common/ChartTabs.vue | 49 +++++++++++++++++------------ 1 file changed, 29 insertions(+), 20 deletions(-) diff --git a/src/components/common/ChartTabs.vue b/src/components/common/ChartTabs.vue index 85ede3c7..2e633428 100644 --- a/src/components/common/ChartTabs.vue +++ b/src/components/common/ChartTabs.vue @@ -65,7 +65,8 @@ export default { leftOffset: 27, // currentTab: '', // tabsData: '', - routerList: [] + routerList: [], + timer: null } }, setup (props) { @@ -105,7 +106,29 @@ export default { } }, mounted () { - this.$nextTick(() => { + this.timer = setTimeout(() => { + this.$nextTick(() => { + this.init() + }) + }, 50) + }, + watch: { + currentTab (n) { + if (this.router === 'noRouter') { + const { query } = this.$route + const newUrl = urlParamsHandler(window.location.href, query, { + tabIndex: n + }) + overwriteUrl(newUrl) + } + + this.$nextTick(() => { + this.handleActiveBar(n) + }) + } + }, + methods: { + init () { // 添加禁用小手 this.tabsData.forEach((item, index) => { if (item.disable) { @@ -127,24 +150,7 @@ export default { this.handleActiveBar(this.currentTab) }) } - }) - }, - watch: { - currentTab (n) { - if (this.router === 'noRouter') { - const { query } = this.$route - const newUrl = urlParamsHandler(window.location.href, query, { - tabIndex: n - }) - overwriteUrl(newUrl) - } - - this.$nextTick(() => { - this.handleActiveBar(n) - }) - } - }, - methods: { + }, handleActiveBar (index) { const tabDom = document.getElementById('tab-' + index) if (tabDom) { @@ -177,6 +183,9 @@ export default { query: query }) } + }, + beforeUnmount () { + clearTimeout(this.timer) } }