update Checkbox

update Checkbox
This commit is contained in:
梁灏 2017-03-15 17:56:50 +08:00
parent 3f281d6ce0
commit 99cde29d04
3 changed files with 31 additions and 21 deletions

View file

@ -27,9 +27,17 @@
<div @click="c">修改1</div>
{{ fruit }}
<Checkbox-group v-model="fruit">
<Checkbox label="香蕉"></Checkbox>
<Checkbox label="苹果"></Checkbox>
<Checkbox label="西瓜"></Checkbox>
<Row>
<i-col span="8">
<Checkbox label="香蕉"></Checkbox>
</i-col>
<i-col span="8">
<Checkbox label="苹果"></Checkbox>
</i-col>
<i-col span="8">
<Checkbox label="西瓜"></Checkbox>
</i-col>
</Row>
</Checkbox-group>
<br><br>
<div style="border-bottom: 1px solid #e9e9e9;padding-bottom:6px;margin-bottom:6px;">

View file

@ -4,6 +4,7 @@
</div>
</template>
<script>
import { findComponentsDownward } from '../../utils/assist';
import Emitter from '../../mixins/emitter';
const prefixCls = 'ivu-checkbox-group';
@ -20,7 +21,8 @@
},
data () {
return {
currentValue: this.value
currentValue: this.value,
childrens: []
};
},
computed: {
@ -34,15 +36,18 @@
methods: {
updateModel (update) {
const value = this.value;
this.childrens = findComponentsDownward(this, 'Checkbox');
this.$children.forEach((child) => {
child.model = value;
if (this.childrens) {
this.childrens.forEach(child => {
child.model = value;
if (update) {
child.currentValue = value.indexOf(child.label) >= 0;
child.group = true;
}
});
if (update) {
child.currentValue = value.indexOf(child.label) >= 0;
child.group = true;
}
});
}
},
change (data) {
this.currentValue = data;

View file

@ -22,6 +22,7 @@
</label>
</template>
<script>
import { findComponentUpward } from '../../utils/assist';
import Emitter from '../../mixins/emitter';
const prefixCls = 'ivu-checkbox';
@ -51,7 +52,8 @@
model: [],
currentValue: this.value,
group: false,
showSlot: true
showSlot: true,
parent: findComponentUpward(this, 'CheckboxGroup')
};
},
computed: {
@ -83,16 +85,11 @@
}
},
mounted () {
// todo 使 while
if (this.$parent && this.$parent.$options.name === 'CheckboxGroup') this.group = true;
this.parent = findComponentUpward(this, 'CheckboxGroup');
if (this.parent) this.group = true;
if (!this.group) {
this.updateModel();
// if (this.$refs.slot && this.$refs.slot.innerHTML === '') {
// this.showSlot = false;
// }
if (this.$slots.default === undefined) {
this.showSlot = false;
}
this.showSlot = this.$slots.default === undefined;
}
},
methods: {
@ -106,7 +103,7 @@
this.$emit('input', checked);
if (this.group) {
this.$parent.change(this.model);
this.parent.change(this.model);
} else {
this.$emit('on-change', checked);
this.dispatch('FormItem', 'on-form-change', checked);