feat: 默认开启/关闭

This commit is contained in:
jiangruowei
2017-04-01 17:07:08 +08:00
parent 5580e2cdce
commit e803525c98
2 changed files with 97 additions and 21 deletions

View File

@@ -13,7 +13,7 @@ import ZanLoading from 'packages/loading';
* zan-switch
* @module components/switch
* @desc 开关
* @param {boolean} [checked=false] - 开关状态
* @param {boolean} [value=false] - 开关状态
* @param {boolean} [disabled=false] - 禁用
* @param {boolean} [loading=false] - loading状态
*
@@ -26,9 +26,24 @@ export default {
'zan-loading': ZanLoading
},
props: {
checked: Boolean,
value: Boolean,
disabled: Boolean,
loading: Boolean
loading: Boolean,
onChange: Function
},
data() {
return {
checked: this.value
}
},
watch: {
checked(val) {
this.$emit('input', val);
},
value(val) {
this.checked = val;
}
},
computed: {
switchStates: function() {
@@ -47,7 +62,12 @@ export default {
*/
toggleState: function() {
if (this.disabled || this.loading) return;
this.$emit('change', !this.checked);
console.log('d');
if (this.onChange) {
this.onChange(!this.checked);
} else {
this.checked = !this.checked;
}
}
}
};