@@ -66,23 +66,17 @@ export default {
6666 decoratorFormProps : { default : ( ) => ( { } ) } ,
6767 collectFormItemContext : { default : ( ) => noop } ,
6868 } ,
69+ created ( ) {
70+ this . collectContext ( ) ;
71+ } ,
6972 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- }
8473 return { helpShow : false } ;
8574 } ,
75+ beforeUpdate ( ) {
76+ if ( process . env . NODE_ENV !== 'production' ) {
77+ this . collectContext ( ) ;
78+ }
79+ } ,
8680 beforeDestroy ( ) {
8781 this . collectFormItemContext ( this . $vnode . context , 'delete' ) ;
8882 } ,
@@ -98,6 +92,24 @@ export default {
9892 ) ;
9993 } ,
10094 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+ } ,
101113 getHelpMessage ( ) {
102114 const help = getComponentFromProp ( this , 'help' ) ;
103115 const onlyControl = this . getOnlyControl ( ) ;
0 commit comments