Browse Source

fix(checkbox、switch): async change value , emit change fn

richard1015 3 years ago
parent
commit
3c0a904cc1

+ 8 - 1
src/packages/__VUE/checkbox/common.ts

@@ -84,7 +84,10 @@ export const component = (componentName: string, nutIcon: object) => {
           : 'nut-checkbox__icon--disable';
       });
 
+      let updateType = '';
+
       const emitChange = (value: string | boolean, label?: string) => {
+        updateType = 'click';
         emit('update:modelValue', value);
         emit('change', value, label);
       };
@@ -92,7 +95,11 @@ export const component = (componentName: string, nutIcon: object) => {
       watch(
         () => props.modelValue,
         (v) => {
-          emit('change', v);
+          if (updateType == 'click') {
+            updateType = '';
+          } else {
+            emit('change', v);
+          }
         }
       );
 

+ 8 - 1
src/packages/__VUE/switch/index.taro.vue

@@ -86,9 +86,12 @@ export default create({
       };
     });
 
+    let updateType = '';
+
     const onClick = (event: Event) => {
       if (props.disable || props.loading) return;
       const value = isActive.value ? props.inactiveValue : props.activeValue;
+      updateType = 'click';
       emit('update:modelValue', value);
       emit('change', value, event);
     };
@@ -96,7 +99,11 @@ export default create({
     watch(
       () => props.modelValue,
       (v) => {
-        emit('change', v);
+        if (updateType == 'click') {
+          updateType = '';
+        } else {
+          emit('change', v);
+        }
       }
     );
 

+ 8 - 1
src/packages/__VUE/switch/index.vue

@@ -86,9 +86,12 @@ export default create({
       };
     });
 
+    let updateType = '';
+
     const onClick = (event: Event) => {
       if (props.disable || props.loading) return;
       const value = isActive.value ? props.inactiveValue : props.activeValue;
+      updateType = 'click';
       emit('update:modelValue', value);
       emit('change', value, event);
     };
@@ -96,7 +99,11 @@ export default create({
     watch(
       () => props.modelValue,
       (v) => {
-        emit('change', v);
+        if (updateType == 'click') {
+          updateType = '';
+        } else {
+          emit('change', v);
+        }
       }
     );