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>
|
<div @click="c">修改1</div>
|
||||||
{{ fruit }}
|
{{ fruit }}
|
||||||
<Checkbox-group v-model="fruit">
|
<Checkbox-group v-model="fruit">
|
||||||
|
<Row>
|
||||||
|
<i-col span="8">
|
||||||
<Checkbox label="香蕉"></Checkbox>
|
<Checkbox label="香蕉"></Checkbox>
|
||||||
|
</i-col>
|
||||||
|
<i-col span="8">
|
||||||
<Checkbox label="苹果"></Checkbox>
|
<Checkbox label="苹果"></Checkbox>
|
||||||
|
</i-col>
|
||||||
|
<i-col span="8">
|
||||||
<Checkbox label="西瓜"></Checkbox>
|
<Checkbox label="西瓜"></Checkbox>
|
||||||
|
</i-col>
|
||||||
|
</Row>
|
||||||
</Checkbox-group>
|
</Checkbox-group>
|
||||||
<br><br>
|
<br><br>
|
||||||
<div style="border-bottom: 1px solid #e9e9e9;padding-bottom:6px;margin-bottom:6px;">
|
<div style="border-bottom: 1px solid #e9e9e9;padding-bottom:6px;margin-bottom:6px;">
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<script>
|
<script>
|
||||||
|
import { findComponentsDownward } from '../../utils/assist';
|
||||||
import Emitter from '../../mixins/emitter';
|
import Emitter from '../../mixins/emitter';
|
||||||
const prefixCls = 'ivu-checkbox-group';
|
const prefixCls = 'ivu-checkbox-group';
|
||||||
|
|
||||||
|
@ -20,7 +21,8 @@
|
||||||
},
|
},
|
||||||
data () {
|
data () {
|
||||||
return {
|
return {
|
||||||
currentValue: this.value
|
currentValue: this.value,
|
||||||
|
childrens: []
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
|
@ -34,8 +36,10 @@
|
||||||
methods: {
|
methods: {
|
||||||
updateModel (update) {
|
updateModel (update) {
|
||||||
const value = this.value;
|
const value = this.value;
|
||||||
|
this.childrens = findComponentsDownward(this, 'Checkbox');
|
||||||
|
|
||||||
this.$children.forEach((child) => {
|
if (this.childrens) {
|
||||||
|
this.childrens.forEach(child => {
|
||||||
child.model = value;
|
child.model = value;
|
||||||
|
|
||||||
if (update) {
|
if (update) {
|
||||||
|
@ -43,6 +47,7 @@
|
||||||
child.group = true;
|
child.group = true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
},
|
},
|
||||||
change (data) {
|
change (data) {
|
||||||
this.currentValue = data;
|
this.currentValue = data;
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
</label>
|
</label>
|
||||||
</template>
|
</template>
|
||||||
<script>
|
<script>
|
||||||
|
import { findComponentUpward } from '../../utils/assist';
|
||||||
import Emitter from '../../mixins/emitter';
|
import Emitter from '../../mixins/emitter';
|
||||||
|
|
||||||
const prefixCls = 'ivu-checkbox';
|
const prefixCls = 'ivu-checkbox';
|
||||||
|
@ -51,7 +52,8 @@
|
||||||
model: [],
|
model: [],
|
||||||
currentValue: this.value,
|
currentValue: this.value,
|
||||||
group: false,
|
group: false,
|
||||||
showSlot: true
|
showSlot: true,
|
||||||
|
parent: findComponentUpward(this, 'CheckboxGroup')
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
|
@ -83,16 +85,11 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
mounted () {
|
mounted () {
|
||||||
// todo 使用 while向上查找
|
this.parent = findComponentUpward(this, 'CheckboxGroup');
|
||||||
if (this.$parent && this.$parent.$options.name === 'CheckboxGroup') this.group = true;
|
if (this.parent) this.group = true;
|
||||||
if (!this.group) {
|
if (!this.group) {
|
||||||
this.updateModel();
|
this.updateModel();
|
||||||
// if (this.$refs.slot && this.$refs.slot.innerHTML === '') {
|
this.showSlot = this.$slots.default === undefined;
|
||||||
// this.showSlot = false;
|
|
||||||
// }
|
|
||||||
if (this.$slots.default === undefined) {
|
|
||||||
this.showSlot = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
@ -106,7 +103,7 @@
|
||||||
this.$emit('input', checked);
|
this.$emit('input', checked);
|
||||||
|
|
||||||
if (this.group) {
|
if (this.group) {
|
||||||
this.$parent.change(this.model);
|
this.parent.change(this.model);
|
||||||
} else {
|
} else {
|
||||||
this.$emit('on-change', checked);
|
this.$emit('on-change', checked);
|
||||||
this.dispatch('FormItem', 'on-form-change', checked);
|
this.dispatch('FormItem', 'on-form-change', checked);
|
||||||
|
|
Loading…
Add table
Reference in a new issue