mirror of
				https://gitee.com/vant-contrib/vant.git
				synced 2025-10-31 03:22:08 +08:00 
			
		
		
		
	[bugfix] Functional component inherit context (#2686)
This commit is contained in:
		
							parent
							
								
									b896113ad6
								
							
						
					
					
						commit
						ef38458a38
					
				| @ -22,10 +22,12 @@ const prefix = (name, mods) => { | ||||
|   } | ||||
| 
 | ||||
|   const ret = {}; | ||||
|   mods && | ||||
|   if (mods) { | ||||
|     Object.keys(mods).forEach(key => { | ||||
|       ret[name + MODS + key] = mods[key]; | ||||
|     }); | ||||
|   } | ||||
| 
 | ||||
|   return ret; | ||||
| }; | ||||
| 
 | ||||
|  | ||||
| @ -30,15 +30,21 @@ function install(Vue) { | ||||
|   Vue.component(camelize(`-${name}`), this); | ||||
| } | ||||
| 
 | ||||
| const inheritKey = ['style', 'class', 'nativeOn', 'directives', 'staticClass', 'staticStyle']; | ||||
| const mapInheritKey = { nativeOn: 'on' }; | ||||
| 
 | ||||
| function functional(sfc) { | ||||
|   const { render } = sfc; | ||||
|   sfc.functional = true; | ||||
|   sfc.render = (h, context) => | ||||
|     render(h, context, { | ||||
|       style: context.data.style, | ||||
|       class: context.data.class, | ||||
|       staticClass: context.data.staticClass | ||||
|     }); | ||||
|   sfc.render = (h, context) => { | ||||
|     const inherit = inheritKey.reduce((obj, key) => { | ||||
|       if (context.data[key]) { | ||||
|         obj[mapInheritKey[key] || key] = context.data[key]; | ||||
|       } | ||||
|       return obj; | ||||
|     }, {}); | ||||
|     return render(h, context, inherit); | ||||
|   }; | ||||
| } | ||||
| 
 | ||||
| export default name => (sfc, isFunctional) => { | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user