iview/components/checkbox/checkbox-group.vue

52 lines
1.2 KiB
Vue
Raw Normal View History

2016-09-09 14:29:19 +08:00
<template>
<div :class="classes">
<slot></slot>
</div>
</template>
<script>
const prefixCls = 'ivu-checkbox-group';
export default {
props: {
model: {
type: Array,
default: []
}
},
computed: {
classes () {
return `${prefixCls}`;
}
},
compiled () {
this.updateModel(true);
},
methods: {
updateModel (update) {
const model = this.model;
this.$children.forEach((child) => {
child.model = model;
if (update) {
child.selected = model.indexOf(child.value) >= 0;
child.group = true;
}
});
},
change (data) {
this.model = data;
2016-09-09 14:29:19 +08:00
this.$emit('on-change', data);
}
},
watch: {
model (val, oldVal) {
if (val == oldVal) {
this.updateModel();
} else {
this.updateModel(true);
}
}
}
}
</script>