support Radio

support Radio
This commit is contained in:
梁灏 2017-03-01 17:01:22 +08:00
parent fc7ef07216
commit 06322514c6
13 changed files with 77 additions and 214 deletions

View file

@ -11,7 +11,7 @@
export default {
name: 'radioGroup',
props: {
model: {
value: {
type: [String, Number],
default: ''
},
@ -30,6 +30,11 @@
default: false
}
},
data () {
return {
currentValue: this.value
}
},
computed: {
classes () {
return [
@ -42,27 +47,29 @@
];
}
},
compiled () {
this.updateModel();
mounted () {
this.updateValue();
},
methods: {
updateModel () {
const model = this.model;
updateValue () {
const value = this.value;
this.$children.forEach((child) => {
child.selected = model == child.value;
child.currentValue = value == child.label;
child.group = true;
});
},
change (data) {
this.model = data.value;
this.updateModel();
this.currentValue = data.value;
this.updateValue();
this.$emit('input', data.value);
this.$emit('on-change', data.value);
this.$dispatch('on-form-change', data.value);
// todo
// this.$dispatch('on-form-change', data.value);
}
},
watch: {
model () {
this.updateModel();
value () {
this.updateValue();
}
}
};