support Checkbox

support Checkbox
This commit is contained in:
梁灏 2017-03-01 17:58:40 +08:00
parent 06322514c6
commit cbe03a12b2
10 changed files with 146 additions and 29 deletions

View file

@ -9,42 +9,49 @@
export default {
name: 'checkboxGroup',
props: {
model: {
value: {
type: Array,
default () {
return [];
}
}
},
data () {
return {
currentValue: this.value
};
},
computed: {
classes () {
return `${prefixCls}`;
}
},
compiled () {
mounted () {
this.updateModel(true);
},
methods: {
updateModel (update) {
const model = this.model;
const value = this.value;
this.$children.forEach((child) => {
child.model = model;
child.model = value;
if (update) {
child.selected = model.indexOf(child.value) >= 0;
child.currentValue = value.indexOf(child.label) >= 0;
child.group = true;
}
});
},
change (data) {
this.model = data;
this.currentValue = data;
this.$emit('input', data);
this.$emit('on-change', data);
this.$dispatch('on-form-change', data);
// todo
// this.$dispatch('on-form-change', data);
}
},
watch: {
model () {
value () {
this.updateModel(true);
}
}