@@ -66,23 +66,17 @@ export default {
66
66
decoratorFormProps : { default : ( ) => ( { } ) } ,
67
67
collectFormItemContext : { default : ( ) => noop } ,
68
68
} ,
69
+ created ( ) {
70
+ this . collectContext ( ) ;
71
+ } ,
69
72
data ( ) {
70
- const { templateContext = { } } = this . FormProps . form || { } ;
71
- const vnodes = Object . values ( templateContext . $slots || { } ) . reduce ( ( a , b ) => {
72
- return [ ...a , ...b ] ;
73
- } , [ ] ) ;
74
- const isSlot = comeFromSlot ( vnodes , this . $vnode ) ;
75
- warning ( ! isSlot , 'You can not set FormItem from slot, please use slot-scope instead slot' ) ;
76
- let isSlotScope = false ;
77
- // 进一步判断是否是通过slot-scope传递
78
- if ( ! isSlot && this . $vnode . context !== templateContext ) {
79
- isSlotScope = comeFromSlot ( this . $vnode . context . $children , templateContext . $vnode ) ;
80
- }
81
- if ( ! isSlotScope && ! isSlot ) {
82
- this . collectFormItemContext ( this . $vnode . context ) ;
83
- }
84
73
return { helpShow : false } ;
85
74
} ,
75
+ beforeUpdate ( ) {
76
+ if ( process . env . NODE_ENV !== 'production' ) {
77
+ this . collectContext ( ) ;
78
+ }
79
+ } ,
86
80
beforeDestroy ( ) {
87
81
this . collectFormItemContext ( this . $vnode . context , 'delete' ) ;
88
82
} ,
@@ -98,6 +92,24 @@ export default {
98
92
) ;
99
93
} ,
100
94
methods : {
95
+ collectContext ( ) {
96
+ if ( this . FormProps . form && this . FormProps . form . templateContext ) {
97
+ const { templateContext } = this . FormProps . form ;
98
+ const vnodes = Object . values ( templateContext . $slots || { } ) . reduce ( ( a , b ) => {
99
+ return [ ...a , ...b ] ;
100
+ } , [ ] ) ;
101
+ const isSlot = comeFromSlot ( vnodes , this . $vnode ) ;
102
+ warning ( ! isSlot , 'You can not set FormItem from slot, please use slot-scope instead slot' ) ;
103
+ let isSlotScope = false ;
104
+ // 进一步判断是否是通过slot-scope传递
105
+ if ( ! isSlot && this . $vnode . context !== templateContext ) {
106
+ isSlotScope = comeFromSlot ( this . $vnode . context . $children , templateContext . $vnode ) ;
107
+ }
108
+ if ( ! isSlotScope && ! isSlot ) {
109
+ this . collectFormItemContext ( this . $vnode . context ) ;
110
+ }
111
+ }
112
+ } ,
101
113
getHelpMessage ( ) {
102
114
const help = getComponentFromProp ( this , 'help' ) ;
103
115
const onlyControl = this . getOnlyControl ( ) ;
0 commit comments