提交 c528eea7 编写于 作者: D dolymood

fix(radio): radio group support v-model when using group

上级 f6d4cf6d
......@@ -20,6 +20,11 @@
export default {
name: COMPONENT_NAME,
provide() {
return {
radioGroup: this
}
},
props: {
value: [String, Number],
options: {
......
......@@ -18,6 +18,11 @@ const EVENT_INPUT = 'input'
export default {
name: COMPONENT_NAME,
inject: {
radioGroup: {
default: null
}
},
props: {
value: [String, Number],
option: {
......@@ -38,6 +43,21 @@ export default {
radioValue: this.value
}
},
created() {
const radioGroup = this.radioGroup
if (radioGroup) {
this.radioValue = radioGroup.radioValue
this._cancelWatchGroup = this.$watch(() => {
return radioGroup.radioValue
}, (newValue) => {
this.radioValue = newValue
})
}
},
beforeDestroy() {
this._cancelWatchGroup && this._cancelWatchGroup()
this._cancelWatchGroup = null
},
watch: {
value(newV) {
this.radioValue = newV
......@@ -47,6 +67,9 @@ export default {
newV = Number(newV)
}
this.$emit(EVENT_INPUT, newV)
if (this.radioGroup) {
this.radioGroup.radioValue = newV
}
}
},
computed: {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册