diff --git a/src/switch/index.js b/src/switch/index.js
index 334e42fe7..b83faf256 100644
--- a/src/switch/index.js
+++ b/src/switch/index.js
@@ -15,57 +15,49 @@ export default createComponent({
props: switchProps,
- emits: ['click', 'change', 'update:modelValue'],
+ emits: ['change', 'update:modelValue'],
- computed: {
- checked() {
- return this.modelValue === this.activeValue;
- },
+ setup(props, { emit }) {
+ const isChecked = () => props.modelValue === props.activeValue;
- style() {
- return {
- fontSize: addUnit(this.size),
- backgroundColor: this.checked ? this.activeColor : this.inactiveColor,
- };
- },
- },
-
- methods: {
- onClick(event) {
- this.$emit('click', event);
-
- if (!this.disabled && !this.loading) {
- const newValue = this.checked ? this.inactiveValue : this.activeValue;
- this.$emit('update:modelValue', newValue);
- this.$emit('change', newValue);
+ const onClick = () => {
+ if (!props.disabled && !props.loading) {
+ const newValue = isChecked() ? props.inactiveValue : props.activeValue;
+ emit('update:modelValue', newValue);
+ emit('change', newValue);
}
- },
+ };
- genLoading() {
- if (this.loading) {
- const color = this.checked ? this.activeColor : this.inactiveColor;
+ const renderLoading = () => {
+ if (props.loading) {
+ const color = isChecked() ? props.activeColor : props.inactiveColor;
return