iview/src/components/radio/radio-group.vue

63 lines
1.6 KiB
Vue
Raw Normal View History

2016-09-09 14:29:19 +08:00
<template>
<div :class="classes">
<slot></slot>
</div>
</template>
<script>
import { oneOf } from '../../utils/assist';
const prefixCls = 'ivu-radio-group';
export default {
props: {
model: {
type: [String, Number],
default: ''
},
size: {
validator (value) {
return oneOf(value, ['small', 'large']);
}
},
type: {
validator (value) {
return oneOf(value, ['button']);
}
}
},
computed: {
classes () {
return [
`${prefixCls}`,
{
[`${prefixCls}-${this.size}`]: !!this.size,
[`${prefixCls}-${this.type}`]: !!this.type
}
2016-12-25 22:49:42 +08:00
];
2016-09-09 14:29:19 +08:00
}
},
compiled () {
this.updateModel();
},
methods: {
updateModel () {
const model = this.model;
this.$children.forEach((child) => {
child.selected = model == child.value;
child.group = true;
});
},
change (data) {
this.model = data.value;
this.updateModel();
this.$emit('on-change', data.value);
}
},
watch: {
model () {
2016-12-25 22:49:42 +08:00
this.updateModel();
2016-09-09 14:29:19 +08:00
}
}
2016-12-25 22:49:42 +08:00
};
</script>