mirror of
https://gitee.com/vant-contrib/vant-weapp.git
synced 2025-04-06 03:58:05 +08:00
[improvement] Switch: optimize computed (#1079)
This commit is contained in:
parent
5aab460b75
commit
329a1f884d
@ -23,13 +23,6 @@ VantComponent({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
computed: {
|
|
||||||
style() {
|
|
||||||
const backgroundColor = this.data.checked ? this.data.activeColor : this.data.inactiveColor;
|
|
||||||
return `font-size: ${this.data.size}; ${ backgroundColor ? `background-color: ${backgroundColor}` : '' }`
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
created() {
|
created() {
|
||||||
this.set({ value: this.data.checked });
|
this.set({ value: this.data.checked });
|
||||||
},
|
},
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
<wxs src="../wxs/utils.wxs" module="utils" />
|
<wxs src="../wxs/utils.wxs" module="utils" />
|
||||||
|
|
||||||
<view
|
<view
|
||||||
style="{{ style }}"
|
|
||||||
class="custom-class {{ utils.bem('switch', { on: checked, disabled }) }}"
|
class="custom-class {{ utils.bem('switch', { on: checked, disabled }) }}"
|
||||||
|
style="font-size: {{ size }}; {{ (checked ? activeColor : inactiveColor) ? 'background-color: ' + (checked ? activeColor : inactiveColor ) : '' }}"
|
||||||
bind:tap="onClick"
|
bind:tap="onClick"
|
||||||
>
|
>
|
||||||
<view class="van-switch__node node-class">
|
<view class="van-switch__node node-class">
|
||||||
|
Loading…
x
Reference in New Issue
Block a user