From 7d6cf7539ccb611aa421c69a12c391ce90c0ef1b Mon Sep 17 00:00:00 2001 From: Stuart Clark Date: Fri, 13 Oct 2023 14:48:56 +1100 Subject: [PATCH] feat(#90): add loading tab by hash (#116) --- src/components/Tabs.vue | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/components/Tabs.vue b/src/components/Tabs.vue index b7f31be..db35db1 100644 --- a/src/components/Tabs.vue +++ b/src/components/Tabs.vue @@ -47,8 +47,8 @@ import ThemeMixin from '../mixins/theme' export default { mixins: [ThemeMixin], - data: ({ tabs, tabId }) => ({ - model: tabId(tabs[0]), + data: ({ hashTab, tabs, tabId }) => ({ + model: hashTab || tabId(tabs[0]), }), props: { @@ -58,6 +58,13 @@ export default { }, }, + computed: { + hashTab: ({ $route }) => + $route.hash + ? $route.hash.slice(1).split('-').slice(0, -1).join('-') + : undefined + }, + methods: { isSelected(tab, delta) { return !!(this.model === this.tabId(tab, delta)) @@ -72,6 +79,10 @@ export default { } }, + mounted() { + if (this.hashTab) this.model = this.hashTab + }, + watch: { model() { this.$emit('input', this.model)