|
4 | 4 | <cube-tab |
5 | 5 | v-for="(item, index) in data" |
6 | 6 | :label="item.label" |
| 7 | + :value="item.value" |
7 | 8 | :icon="item.icon" |
8 | | - :key="item.label"> |
| 9 | + :key="item.value || item.label"> |
9 | 10 | </cube-tab> |
10 | 11 | </slot> |
11 | 12 | <div v-if="showSlider" ref="slider" class="cube-tab-bar-slider"></div> |
|
54 | 55 | default: true |
55 | 56 | } |
56 | 57 | }, |
| 58 | + watch: { |
| 59 | + value () { |
| 60 | + this._updateSliderStyle() |
| 61 | + } |
| 62 | + }, |
57 | 63 | created () { |
58 | 64 | this.tabs = [] |
59 | 65 | }, |
|
81 | 87 | const index = this.tabs.indexOf(tab) |
82 | 88 | if (index > -1) this.tabs.splice(index, 1) |
83 | 89 | }, |
84 | | - trigger (label) { |
| 90 | + trigger (value) { |
85 | 91 | // emit click event as long as tab is clicked |
86 | | - this.$emit(EVENT_CLICK, label) |
| 92 | + this.$emit(EVENT_CLICK, value) |
87 | 93 | // only when value changed, emit change & input event |
88 | | - if (label !== this.value) { |
| 94 | + if (value !== this.value) { |
89 | 95 | const changedEvents = [EVENT_INPUT, EVENT_CHANGE] |
90 | 96 | changedEvents.forEach((eventType) => { |
91 | | - this.$emit(eventType, label) |
| 97 | + this.$emit(eventType, value) |
92 | 98 | }) |
93 | 99 | } |
94 | 100 | }, |
|
116 | 122 | let width = 0 |
117 | 123 | let index = 0 |
118 | 124 | if (this.tabs.length > 0) { |
119 | | - index = findIndex(this.tabs, (tab) => tab.label === this.value) |
| 125 | + index = findIndex(this.tabs, (tab) => tab.value === this.value) |
120 | 126 | width = this.tabs[index].$el.clientWidth |
121 | 127 | } |
122 | 128 | return { |
|
141 | 147 | clearTimeout(this._resizeTimer) |
142 | 148 | window.removeEventListener('resize', this._resizeHandler) |
143 | 149 | } |
144 | | - }, |
145 | | - watch: { |
146 | | - value () { |
147 | | - this._updateSliderStyle() |
148 | | - } |
149 | 150 | } |
150 | 151 | } |
151 | 152 | </script> |
|
0 commit comments