-
Notifications
You must be signed in to change notification settings - Fork 0
/
Tabs.vue
51 lines (42 loc) · 1.13 KB
/
Tabs.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<template>
<div>
<ul class="nav nav-tabs" role="tablist">
<li role="presentation" v-for="tab in tabs" :class="{active: tab.active}">
<a :href="tab.href" @click="select(tab)" aria-controls="team" role="tab">
{{ tab.name }}
</a>
</li>
</ul>
<div class="tab-content">
<slot></slot>
</div>
</div>
</template>
<script>
export default {
data(){
return {
tabs: [],
}
},
methods: {
select(tab){
this.tabs.forEach(x => x.active = (tab === x));
},
selectFromHash(){
let active = this.tabs.find(x => x.href === window.location.hash);
if (active){
this.select(active);
}
}
},
mounted() {
this.tabs = this.$children;
window.addEventListener('hashchange', this.selectFromHash, false);
this.selectFromHash();
},
destroyed() {
window.removeEventListener('hashchange', this.selectFromHash);
}
}
</script>