update Checkbox
update Checkbox
This commit is contained in:
parent
3f281d6ce0
commit
99cde29d04
3 changed files with 31 additions and 21 deletions
|
@ -27,9 +27,17 @@
|
|||
<div @click="c">修改1</div>
|
||||
{{ fruit }}
|
||||
<Checkbox-group v-model="fruit">
|
||||
<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;">
|
||||
|
|
|
@ -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,8 +36,10 @@
|
|||
methods: {
|
||||
updateModel (update) {
|
||||
const value = this.value;
|
||||
this.childrens = findComponentsDownward(this, 'Checkbox');
|
||||
|
||||
this.$children.forEach((child) => {
|
||||
if (this.childrens) {
|
||||
this.childrens.forEach(child => {
|
||||
child.model = value;
|
||||
|
||||
if (update) {
|
||||
|
@ -43,6 +47,7 @@
|
|||
child.group = true;
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
change (data) {
|
||||
this.currentValue = data;
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Add table
Reference in a new issue