fix: 修复ChartTabs组件初始化时activeBar异位问题

This commit is contained in:
刘洪洪
2022-12-07 09:40:21 +08:00
parent 4b70065abe
commit 2a1921fdbc

View File

@@ -65,7 +65,8 @@ export default {
leftOffset: 27, leftOffset: 27,
// currentTab: '', // currentTab: '',
// tabsData: '', // tabsData: '',
routerList: [] routerList: [],
timer: null
} }
}, },
setup (props) { setup (props) {
@@ -105,7 +106,29 @@ export default {
} }
}, },
mounted () { mounted () {
this.timer = setTimeout(() => {
this.$nextTick(() => { 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) => { this.tabsData.forEach((item, index) => {
if (item.disable) { if (item.disable) {
@@ -127,24 +150,7 @@ export default {
this.handleActiveBar(this.currentTab) 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) { handleActiveBar (index) {
const tabDom = document.getElementById('tab-' + index) const tabDom = document.getElementById('tab-' + index)
if (tabDom) { if (tabDom) {
@@ -177,6 +183,9 @@ export default {
query: query query: query
}) })
} }
},
beforeUnmount () {
clearTimeout(this.timer)
} }
} }
</script> </script>