Browse Source

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

richard1015 3 years ago
parent
commit
7732d2df4e
2 changed files with 16 additions and 4 deletions
  1. 8 2
      src/packages/__VUE/switch/index.taro.vue
  2. 8 2
      src/packages/__VUE/switch/index.vue

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

@@ -12,7 +12,7 @@
 </template>
 
 <script lang="ts">
-import { computed } from 'vue';
+import { computed, watch } from 'vue';
 import { createComponent } from '@/packages/utils/create';
 const { componentName, create } = createComponent('switch');
 
@@ -90,10 +90,16 @@ export default create({
       if (props.disable || props.loading) return;
       const value = isActive.value ? props.inactiveValue : props.activeValue;
       emit('update:modelValue', value);
-      emit('update:loading');
       emit('change', value, event);
     };
 
+    watch(
+      () => props.modelValue,
+      (v) => {
+        emit('change', v);
+      }
+    );
+
     return {
       classes,
       style,

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

@@ -12,7 +12,7 @@
 </template>
 
 <script lang="ts">
-import { computed } from 'vue';
+import { computed, watch } from 'vue';
 import { createComponent } from '@/packages/utils/create';
 const { componentName, create } = createComponent('switch');
 
@@ -90,10 +90,16 @@ export default create({
       if (props.disable || props.loading) return;
       const value = isActive.value ? props.inactiveValue : props.activeValue;
       emit('update:modelValue', value);
-      emit('update:loading');
       emit('change', value, event);
     };
 
+    watch(
+      () => props.modelValue,
+      (v) => {
+        emit('change', v);
+      }
+    );
+
     return {
       classes,
       style,