-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtabs.js
81 lines (63 loc) · 1.15 KB
/
tabs.js
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
Vue.component('tabs', {
template: `
<div>
<div class="tabs is-centered">
<ul>
<li v-for="tab in tabs" :class="{ 'is-active': tab.isActive }">
<a :href="tab.href" @click="selectTab(tab)">{{ tab.name }}</a>
</li>
</ul>
</div>
<div class="tab-details">
<slot></slot>
</div>
</div>
`,
data() {
return {
tabs: []
};
},
methods: {
selectTab(selectedTab) {
this.tabs.forEach(tab => {
tab.isActive = tab.name == selectedTab.name;
});
}
},
created() {
this.tabs = this.$children;
},
mounted() {
console.log(this.$children.forEach(tab => console.log(tab.name)));
}
});
Vue.component('tab', {
template: `
<div v-show="isActive"><slot></slot></div>
`,
props: {
'name': {
required: true
},
'selected': {
default: false
}
},
computed: {
href() {
return '#' + this.name.toLowerCase().replace(/ /g, '-');
}
},
data() {
return {
isActive: false
};
},
mounted() {
this.isActive = this.selected;
}
});
let app = new Vue({
el: "#root"
});