mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-05-23 06:59:15 +08:00
[improvement] Switch: jsx (#2654)
This commit is contained in:
parent
f397f18a38
commit
1c70cf6ead
@ -1,27 +1,9 @@
|
|||||||
<template>
|
import { use } from '../utils';
|
||||||
<div
|
import Loading from '../loading';
|
||||||
:class="b({
|
|
||||||
on: value === activeValue,
|
|
||||||
disabled
|
|
||||||
})"
|
|
||||||
:style="style"
|
|
||||||
@click="onClick"
|
|
||||||
>
|
|
||||||
<div :class="b('node')">
|
|
||||||
<loading
|
|
||||||
v-if="loading"
|
|
||||||
:class="b('loading')"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script>
|
const [sfc, bem] = use('switch');
|
||||||
import create from '../utils/create';
|
|
||||||
|
|
||||||
export default create({
|
|
||||||
name: 'switch',
|
|
||||||
|
|
||||||
|
export default sfc({
|
||||||
props: {
|
props: {
|
||||||
value: null,
|
value: null,
|
||||||
loading: Boolean,
|
loading: Boolean,
|
||||||
@ -42,15 +24,6 @@ export default create({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
computed: {
|
|
||||||
style() {
|
|
||||||
return {
|
|
||||||
fontSize: this.size,
|
|
||||||
backgroundColor: this.value ? this.activeColor : this.inactiveColor
|
|
||||||
};
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
onClick() {
|
onClick() {
|
||||||
if (!this.disabled && !this.loading) {
|
if (!this.disabled && !this.loading) {
|
||||||
@ -60,6 +33,26 @@ export default create({
|
|||||||
this.$emit('change', 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>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
</script>
|
|
Loading…
x
Reference in New Issue
Block a user