From cb75cdfa350ca1cd96720be39fb952f9f01f4d90 Mon Sep 17 00:00:00 2001 From: paradisehell Date: Fri, 14 Jan 2022 00:09:47 +0800 Subject: [PATCH] feat($theme-default): `CodeGroup` supports changing tab automatically --- .../@vuepress/theme-default/global-components/CodeGroup.vue | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/@vuepress/theme-default/global-components/CodeGroup.vue b/packages/@vuepress/theme-default/global-components/CodeGroup.vue index ac6ec55436..6051ab3da0 100644 --- a/packages/@vuepress/theme-default/global-components/CodeGroup.vue +++ b/packages/@vuepress/theme-default/global-components/CodeGroup.vue @@ -45,10 +45,16 @@ export default { }, mounted () { this.loadTabs() + this.$root.$on('changeAllCodeTab', (index) => { + if (this.activeCodeTabIndex !== index) { + this.changeCodeTab(index) + } + }) }, methods: { changeCodeTab (index) { this.activeCodeTabIndex = index + this.$root.$emit('changeAllCodeTab', index) }, loadTabs () { this.codeTabs = (this.$slots.default || []).filter(slot => Boolean(slot.componentOptions)).map((slot, index) => {