mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
42 lines
968 B
JavaScript
42 lines
968 B
JavaScript
import { use } from '../utils';
|
|
import Loading from '../loading';
|
|
import SwitchMixin from '../mixins/switch';
|
|
|
|
const [sfc, bem] = use('switch');
|
|
|
|
export default sfc({
|
|
mixins: [SwitchMixin],
|
|
|
|
methods: {
|
|
onClick() {
|
|
if (!this.disabled && !this.loading) {
|
|
const checked = this.value === this.activeValue;
|
|
const value = checked ? this.inactiveValue : this.activeValue;
|
|
this.$emit('input', value);
|
|
this.$emit('change', value);
|
|
}
|
|
}
|
|
},
|
|
|
|
render(h) {
|
|
const { value } = this;
|
|
const style = {
|
|
fontSize: this.size,
|
|
backgroundColor: value ? this.activeColor : this.inactiveColor
|
|
};
|
|
|
|
return (
|
|
<div
|
|
class={bem({
|
|
on: value === this.activeValue,
|
|
disabled: this.disabled
|
|
})}
|
|
style={style}
|
|
onClick={this.onClick}
|
|
>
|
|
<div class={bem('node')}>{this.loading && <Loading class={bem('loading')} />}</div>
|
|
</div>
|
|
);
|
|
}
|
|
});
|