2019-02-18 13:36:00 +08:00

50 lines
1.0 KiB
JavaScript

import { VantComponent } from '../common/component';
VantComponent({
field: true,
classes: ['node-class'],
props: {
checked: null,
loading: Boolean,
disabled: Boolean,
activeColor: String,
inactiveColor: String,
size: {
type: String,
value: '30px'
},
activeValue: {
type: null,
value: true
},
inactiveValue: {
type: null,
value: false
}
},
watch: {
checked: function checked(value) {
this.set({
value: value
});
}
},
created: function created() {
this.set({
value: this.data.checked
});
},
methods: {
onClick: function onClick() {
var _this$data = this.data,
activeValue = _this$data.activeValue,
inactiveValue = _this$data.inactiveValue;
if (!this.data.disabled && !this.data.loading) {
var checked = this.data.checked === activeValue;
var value = checked ? inactiveValue : activeValue;
this.$emit('input', value);
this.$emit('change', value);
}
}
}
});