update RadioGroup
update RadioGroup
This commit is contained in:
parent
4f5d393734
commit
3f281d6ce0
4 changed files with 62 additions and 42 deletions
|
@ -1,28 +1,27 @@
|
||||||
<template>
|
<template>
|
||||||
<div>
|
<div>
|
||||||
<Radio v-model="single" @on-change="c">Radio</Radio>
|
<Radio-group v-model="phone">
|
||||||
<Radio-group v-model="phone" type="button" @on-change="c">
|
<Row>
|
||||||
<Radio label="apple">
|
<i-col span="8">
|
||||||
<Icon type="social-apple"></Icon>
|
<Radio label="apple">
|
||||||
<span>Apple</span>
|
<Icon type="social-apple"></Icon>
|
||||||
</Radio>
|
<span>Apple</span>
|
||||||
<Radio label="android">
|
</Radio>
|
||||||
<Icon type="social-android"></Icon>
|
</i-col>
|
||||||
<span>Android</span>
|
<i-col span="8">
|
||||||
</Radio>
|
<Radio label="android">
|
||||||
<Radio label="windows">
|
<Icon type="social-android"></Icon>
|
||||||
<Icon type="social-windows"></Icon>
|
<span>Android</span>
|
||||||
<span>Windows</span>
|
</Radio>
|
||||||
</Radio>
|
</i-col>
|
||||||
|
<i-col span="8">
|
||||||
|
<Radio label="windows">
|
||||||
|
<Icon type="social-windows"></Icon>
|
||||||
|
<span>Windows</span>
|
||||||
|
</Radio>
|
||||||
|
</i-col>
|
||||||
|
</Row>
|
||||||
</Radio-group>
|
</Radio-group>
|
||||||
<Radio-group v-model="animal">
|
|
||||||
<Radio label="金斑蝶"></Radio>
|
|
||||||
<Radio label="爪哇犀牛"></Radio>
|
|
||||||
<Radio label="印度黑羚"></Radio>
|
|
||||||
</Radio-group>
|
|
||||||
{{ phone }}
|
|
||||||
<div @click="phone = 'apple'">apple</div>
|
|
||||||
<div @click="single = true"> single</div>{{ single }}
|
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<script>
|
<script>
|
||||||
|
@ -30,13 +29,7 @@
|
||||||
data () {
|
data () {
|
||||||
return {
|
return {
|
||||||
phone: 'apple',
|
phone: 'apple',
|
||||||
animal: '爪哇犀牛',
|
animal: '爪哇犀牛'
|
||||||
single: false
|
|
||||||
}
|
|
||||||
},
|
|
||||||
methods: {
|
|
||||||
c (data) {
|
|
||||||
console.log(data)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<script>
|
<script>
|
||||||
import { oneOf } from '../../utils/assist';
|
import { oneOf, findComponentsDownward } from '../../utils/assist';
|
||||||
import Emitter from '../../mixins/emitter';
|
import Emitter from '../../mixins/emitter';
|
||||||
|
|
||||||
const prefixCls = 'ivu-radio-group';
|
const prefixCls = 'ivu-radio-group';
|
||||||
|
@ -34,7 +34,8 @@
|
||||||
},
|
},
|
||||||
data () {
|
data () {
|
||||||
return {
|
return {
|
||||||
currentValue: this.value
|
currentValue: this.value,
|
||||||
|
childrens: []
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
|
@ -55,10 +56,14 @@
|
||||||
methods: {
|
methods: {
|
||||||
updateValue () {
|
updateValue () {
|
||||||
const value = this.value;
|
const value = this.value;
|
||||||
this.$children.forEach((child) => {
|
this.childrens = findComponentsDownward(this, 'Radio');
|
||||||
child.currentValue = value == child.label;
|
|
||||||
child.group = true;
|
if (this.childrens) {
|
||||||
});
|
this.childrens.forEach(child => {
|
||||||
|
child.currentValue = value == child.label;
|
||||||
|
child.group = true;
|
||||||
|
});
|
||||||
|
}
|
||||||
},
|
},
|
||||||
change (data) {
|
change (data) {
|
||||||
this.currentValue = data.value;
|
this.currentValue = data.value;
|
||||||
|
|
|
@ -12,6 +12,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-radio';
|
const prefixCls = 'ivu-radio';
|
||||||
|
@ -35,7 +36,8 @@
|
||||||
data () {
|
data () {
|
||||||
return {
|
return {
|
||||||
currentValue: this.value,
|
currentValue: this.value,
|
||||||
group: false
|
group: false,
|
||||||
|
parent: findComponentUpward(this, 'RadioGroup')
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
|
@ -66,8 +68,8 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
mounted () {
|
mounted () {
|
||||||
// todo 使用 while向上查找
|
this.parent = findComponentUpward(this, 'RadioGroup');
|
||||||
if (this.$parent && this.$parent.$options.name === 'RadioGroup') this.group = true;
|
if (this.parent) this.group = true;
|
||||||
if (!this.group) {
|
if (!this.group) {
|
||||||
this.updateValue();
|
this.updateValue();
|
||||||
}
|
}
|
||||||
|
@ -83,7 +85,7 @@
|
||||||
this.$emit('input', checked);
|
this.$emit('input', checked);
|
||||||
|
|
||||||
if (this.group && this.label) {
|
if (this.group && this.label) {
|
||||||
this.$parent.change({
|
this.parent.change({
|
||||||
value: this.label,
|
value: this.label,
|
||||||
checked: this.value
|
checked: this.value
|
||||||
});
|
});
|
||||||
|
|
|
@ -185,9 +185,9 @@ function findComponentUpward (content, componentName, componentNames) {
|
||||||
}
|
}
|
||||||
export {findComponentUpward};
|
export {findComponentUpward};
|
||||||
|
|
||||||
// Find components downward
|
// Find component downward
|
||||||
function findComponentDownward (content, componentName) {
|
function findComponentDownward (content, componentName) {
|
||||||
let childrens = content.$children;
|
const childrens = content.$children;
|
||||||
let children = null;
|
let children = null;
|
||||||
|
|
||||||
if (childrens.length) {
|
if (childrens.length) {
|
||||||
|
@ -212,4 +212,24 @@ function findComponentDownward (content, componentName) {
|
||||||
}
|
}
|
||||||
return children;
|
return children;
|
||||||
}
|
}
|
||||||
export {findComponentDownward};
|
export {findComponentDownward};
|
||||||
|
|
||||||
|
// Find components downward
|
||||||
|
function findComponentsDownward (content, componentName, components = []) {
|
||||||
|
const childrens = content.$children;
|
||||||
|
|
||||||
|
if (childrens.length) {
|
||||||
|
childrens.forEach(child => {
|
||||||
|
const name = child.$options.name;
|
||||||
|
const childs = child.$children;
|
||||||
|
|
||||||
|
if (name === componentName) components.push(child);
|
||||||
|
if (childs.length) {
|
||||||
|
const findChilds = findComponentsDownward(child, componentName, components);
|
||||||
|
if (findChilds) components.concat(findChilds);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return components;
|
||||||
|
}
|
||||||
|
export {findComponentsDownward};
|
Loading…
Add table
Reference in a new issue