update RadioGroup
update RadioGroup
This commit is contained in:
parent
4f5d393734
commit
3f281d6ce0
4 changed files with 62 additions and 42 deletions
|
@ -4,7 +4,7 @@
|
|||
</div>
|
||||
</template>
|
||||
<script>
|
||||
import { oneOf } from '../../utils/assist';
|
||||
import { oneOf, findComponentsDownward } from '../../utils/assist';
|
||||
import Emitter from '../../mixins/emitter';
|
||||
|
||||
const prefixCls = 'ivu-radio-group';
|
||||
|
@ -34,7 +34,8 @@
|
|||
},
|
||||
data () {
|
||||
return {
|
||||
currentValue: this.value
|
||||
currentValue: this.value,
|
||||
childrens: []
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
|
@ -55,10 +56,14 @@
|
|||
methods: {
|
||||
updateValue () {
|
||||
const value = this.value;
|
||||
this.$children.forEach((child) => {
|
||||
child.currentValue = value == child.label;
|
||||
child.group = true;
|
||||
});
|
||||
this.childrens = findComponentsDownward(this, 'Radio');
|
||||
|
||||
if (this.childrens) {
|
||||
this.childrens.forEach(child => {
|
||||
child.currentValue = value == child.label;
|
||||
child.group = true;
|
||||
});
|
||||
}
|
||||
},
|
||||
change (data) {
|
||||
this.currentValue = data.value;
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
</label>
|
||||
</template>
|
||||
<script>
|
||||
import { findComponentUpward } from '../../utils/assist';
|
||||
import Emitter from '../../mixins/emitter';
|
||||
|
||||
const prefixCls = 'ivu-radio';
|
||||
|
@ -35,7 +36,8 @@
|
|||
data () {
|
||||
return {
|
||||
currentValue: this.value,
|
||||
group: false
|
||||
group: false,
|
||||
parent: findComponentUpward(this, 'RadioGroup')
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
|
@ -66,8 +68,8 @@
|
|||
}
|
||||
},
|
||||
mounted () {
|
||||
// todo 使用 while向上查找
|
||||
if (this.$parent && this.$parent.$options.name === 'RadioGroup') this.group = true;
|
||||
this.parent = findComponentUpward(this, 'RadioGroup');
|
||||
if (this.parent) this.group = true;
|
||||
if (!this.group) {
|
||||
this.updateValue();
|
||||
}
|
||||
|
@ -83,7 +85,7 @@
|
|||
this.$emit('input', checked);
|
||||
|
||||
if (this.group && this.label) {
|
||||
this.$parent.change({
|
||||
this.parent.change({
|
||||
value: this.label,
|
||||
checked: this.value
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue