feat: migrate Checkbox/CheckboxGroup

This commit is contained in:
chenjiahan
2020-08-15 07:12:09 +08:00
parent 6f4c8f1e5b
commit cef8daf717
5 changed files with 32 additions and 26 deletions
+9 -7
View File
@@ -12,27 +12,29 @@ export default createComponent({
}),
],
emits: ['click', 'change', 'update:modelValue'],
computed: {
checked: {
get() {
if (this.parent) {
return this.parent.value.indexOf(this.name) !== -1;
return this.parent.modelValue.indexOf(this.name) !== -1;
}
return this.value;
return this.modelValue;
},
set(val) {
if (this.parent) {
this.setParentValue(val);
} else {
this.$emit('input', val);
this.$emit('update:modelValue', val);
}
},
},
},
watch: {
value(val) {
modelValue(val) {
this.$emit('change', val);
},
},
@@ -51,7 +53,7 @@ export default createComponent({
setParentValue(val) {
const { parent } = this;
const value = parent.value.slice();
const value = parent.modelValue.slice();
if (val) {
if (parent.max && value.length >= parent.max) {
@@ -61,7 +63,7 @@ export default createComponent({
/* istanbul ignore else */
if (value.indexOf(this.name) === -1) {
value.push(this.name);
parent.$emit('input', value);
parent.$emit('update:modelValue', value);
}
} else {
const index = value.indexOf(this.name);
@@ -69,7 +71,7 @@ export default createComponent({
/* istanbul ignore else */
if (index !== -1) {
value.splice(index, 1);
parent.$emit('input', value);
parent.$emit('update:modelValue', value);
}
}
},