|
2 | 2 | <view :class="[styleType === 'text'?'segmented-control--text' : 'segmented-control--button' ]"
|
3 | 3 | :style="{ borderColor: styleType === 'text' ? '' : activeColor }" class="segmented-control">
|
4 | 4 | <view v-for="(item, index) in values" :class="[styleType === 'text' ? '' : 'segmented-control__item--button',
|
5 |
| - index === currentIndex && styleType === 'button' ? 'segmented-control__item--button--active' : '', |
6 | 5 | index === 0 && styleType === 'button' ? 'segmented-control__item--button--first' : '',
|
7 |
| - index === values.length - 1 && styleType === 'button' ? 'segmented-control__item--button--last':'']" :key="index" :style="{backgroundColor: index === currentIndex && styleType === 'button' ? activeColor : styleType === 'button' ?inActiveColor:'transparent', borderColor: index === currentIndex && styleType === 'text' || styleType === 'button' ? activeColor : inActiveColor}" class="segmented-control__item" @click="_onClick(index)"> |
| 6 | + index === values.length - 1 && styleType === 'button' ? 'segmented-control__item--button--last':'']" :key="index" |
| 7 | + :style="{backgroundColor: index === currentIndex && styleType === 'button' ? activeColor : styleType === 'button' ?inActiveColor:'transparent', borderColor: index === currentIndex && styleType === 'text' || styleType === 'button' ? activeColor : inActiveColor}" |
| 8 | + class="segmented-control__item" @click="_onClick(index)"> |
8 | 9 | <view>
|
9 | 10 | <text
|
10 |
| - :style="index===currentIndex?{color : styleType === 'text' ? activeColor : '#fff'}:{color : styleType === 'text' ?'#000' : activeColor}" |
| 11 | + :style="{color:index === currentIndex? styleType === 'text'? activeColor: '#fff': styleType === 'text'? '#000': activeColor}" |
11 | 12 | class="segmented-control__text"
|
12 | 13 | :class="styleType === 'text' && index === currentIndex ? 'segmented-control__item--text': ''">{{ item }}</text>
|
13 | 14 | </view>
|
|
70 | 71 | }
|
71 | 72 | }
|
72 | 73 | },
|
73 |
| - computed: { |
74 |
| - getTextStyle() { |
75 |
| - return (index) => { |
76 |
| - let style = {}; |
77 |
| - if (index === this.currentIndex) { |
78 |
| - style.color = this.styleType === 'text' ? this.activeColor : '#fff'; |
79 |
| - } else { |
80 |
| - style.color = this.styleType === 'text' ? |
81 |
| - '#000' : this.activeColor; |
82 |
| - } |
83 |
| - return style; |
84 |
| - } |
85 |
| - }, |
86 |
| - computedBackgroundClass() { |
87 |
| - return index => [this.styleType === 'text' ? '' : 'segmented-control__item--button', |
88 |
| - index === this.currentIndex && this.styleType === 'button' ? 'segmented-control__item--button--active' : '', |
89 |
| - index === 0 && this.styleType === 'button' ? 'segmented-control__item--button--first' : '', |
90 |
| - index === this.values.length - 1 && this.styleType === 'button' ? 'segmented-control__item--button--last' : |
91 |
| - '' |
92 |
| - ] |
93 |
| - }, |
94 |
| - computedBackgroundStyle() { |
95 |
| - return index => { |
96 |
| - return { |
97 |
| - backgroundColor: index === this.currentIndex && this.styleType === 'button' ? this.activeColor : this |
98 |
| - .styleType === 'button' ? this.inActiveColor : 'transparent', |
99 |
| - borderColor: index === this.currentIndex && this.styleType === 'text' || this.styleType === 'button' ? this |
100 |
| - .activeColor : this.inActiveColor |
101 |
| - } |
102 |
| - } |
103 |
| - } |
104 |
| - }, |
| 74 | + computed: {}, |
105 | 75 | created() {
|
106 | 76 | this.currentIndex = this.current
|
107 | 77 | },
|
|
0 commit comments