You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
1.1 KiB
JavaScript
44 lines
1.1 KiB
JavaScript
6 months ago
|
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(value) {
|
||
|
this.set({ value });
|
||
|
}
|
||
|
},
|
||
|
created() {
|
||
|
this.set({ value: this.data.checked });
|
||
|
},
|
||
|
methods: {
|
||
|
onClick() {
|
||
|
const { activeValue, inactiveValue } = this.data;
|
||
|
if (!this.data.disabled && !this.data.loading) {
|
||
|
const checked = this.data.checked === activeValue;
|
||
|
const value = checked ? inactiveValue : activeValue;
|
||
|
this.$emit('input', value);
|
||
|
this.$emit('change', value);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
});
|