Skip to content

Commit bf369fc

Browse files
[Tabs component] made the tabs be able to be set using :value and it will emit a input that can be used for vuex and vue-router
1 parent fb2b44d commit bf369fc

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

components/tab.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template>
2-
<div role="tabpanel" class="tab-pane" :class="{active: active, disabled: disabled, fade: fade, in: animate}">
2+
<div role="tabpanel" class="tab-pane" :class="{active: active, disabled: disabled, fade: fade, in: animate, show: active}">
33
<slot></slot>
44
</div>
55
</template>

components/tabs.vue

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@
2424
export default {
2525
replace: true,
2626
data() {
27+
let currentTab = this.value || 0
2728
return {
29+
currentTab,
2830
items: []
2931
};
3032
},
@@ -41,6 +43,18 @@
4143
size: {
4244
type: String,
4345
default: 'md'
46+
},
47+
value: {
48+
type: Number,
49+
default: 0
50+
}
51+
},
52+
watch: {
53+
currentTab (val) {
54+
this.$emit('input', val)
55+
},
56+
value (val) {
57+
this.setActive(val);
4458
}
4559
},
4660
methods: {
@@ -85,12 +99,15 @@
8599
this.$set(this.$children[index], 'animate', true);
86100
this.$root.$emit('changed::tab', this.items[index].id);
87101
}, this.fade ? TRANSITION_DURATION : 0);
102+
103+
// store currentActive
104+
this.currentTab = index
88105
}
89106
},
90107
mounted() {
91108
// if no active tab, set the first one by default
92109
if (this.getActive() === -1) {
93-
this.setActive(0);
110+
this.setActive(this.currentTab);
94111
}
95112
},
96113
destroyed() {

0 commit comments

Comments
 (0)