Browse Source

upd: 修改disable状态下不分发事件

suzigang 5 years ago
parent
commit
bdcb03b7e7
2 changed files with 5 additions and 6 deletions
  1. 1 1
      src/packages/switch/demo.vue
  2. 4 5
      src/packages/switch/switch.vue

+ 1 - 1
src/packages/switch/demo.vue

@@ -38,7 +38,7 @@
         <span slot="title"><nut-switch :disabled="true"></nut-switch></span>
         <span slot="title"><nut-switch :disabled="true"></nut-switch></span>
       </nut-cell>
       </nut-cell>
       <nut-cell>
       <nut-cell>
-        <span slot="title"><nut-switch @change="onChange" :active="true" :disabled="true"></nut-switch></span>
+        <span slot="title"><nut-switch :active="true" :disabled="true"></nut-switch></span>
       </nut-cell>
       </nut-cell>
     </div>
     </div>
     <p>禁用状态下,change事件参数永远为初始值</p>
     <p>禁用状态下,change事件参数永远为初始值</p>

+ 4 - 5
src/packages/switch/switch.vue

@@ -45,12 +45,11 @@ export default {
       const status = this.isActive;
       const status = this.isActive;
       if (!this.disabled) {
       if (!this.disabled) {
         this.isActive = !status;
         this.isActive = !status;
+        setTimeout(() => {
+          this.$emit('change', this.isActive);
+          this.$emit('update:active', this.isActive);
+        }, 300);
       }
       }
-
-      setTimeout(() => {
-        this.$emit('change', this.isActive);
-        this.$emit('update:active', this.isActive);
-      }, 300);
     }
     }
   }
   }
 };
 };