File tree Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Original file line number Diff line number Diff line change 2020
2121 export default {
2222 name: COMPONENT_NAME ,
23+ provide () {
24+ return {
25+ radioGroup: this
26+ }
27+ },
2328 props: {
2429 value: [String , Number ],
2530 options: {
Original file line number Diff line number Diff line change @@ -18,6 +18,11 @@ const EVENT_INPUT = 'input'
1818
1919export default {
2020 name: COMPONENT_NAME ,
21+ inject: {
22+ radioGroup: {
23+ default: null
24+ }
25+ },
2126 props: {
2227 value: [String , Number ],
2328 option: {
@@ -38,6 +43,21 @@ export default {
3843 radioValue: this .value
3944 }
4045 },
46+ created () {
47+ const radioGroup = this .radioGroup
48+ if (radioGroup) {
49+ this .radioValue = radioGroup .radioValue
50+ this ._cancelWatchGroup = this .$watch (() => {
51+ return radioGroup .radioValue
52+ }, (newValue ) => {
53+ this .radioValue = newValue
54+ })
55+ }
56+ },
57+ beforeDestroy () {
58+ this ._cancelWatchGroup && this ._cancelWatchGroup ()
59+ this ._cancelWatchGroup = null
60+ },
4161 watch: {
4262 value (newV ) {
4363 this .radioValue = newV
@@ -47,6 +67,9 @@ export default {
4767 newV = Number (newV)
4868 }
4969 this .$emit (EVENT_INPUT , newV)
70+ if (this .radioGroup ) {
71+ this .radioGroup .radioValue = newV
72+ }
5073 }
5174 },
5275 computed: {
You can’t perform that action at this time.
0 commit comments