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 = {}; |   const ret = {}; | ||||||
|   mods && |   if (mods) { | ||||||
|     Object.keys(mods).forEach(key => { |     Object.keys(mods).forEach(key => { | ||||||
|       ret[name + MODS + key] = mods[key]; |       ret[name + MODS + key] = mods[key]; | ||||||
|     }); |     }); | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|   return ret; |   return ret; | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -30,15 +30,21 @@ function install(Vue) { | |||||||
|   Vue.component(camelize(`-${name}`), this); |   Vue.component(camelize(`-${name}`), this); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | const inheritKey = ['style', 'class', 'nativeOn', 'directives', 'staticClass', 'staticStyle']; | ||||||
|  | const mapInheritKey = { nativeOn: 'on' }; | ||||||
|  | 
 | ||||||
| function functional(sfc) { | function functional(sfc) { | ||||||
|   const { render } = sfc; |   const { render } = sfc; | ||||||
|   sfc.functional = true; |   sfc.functional = true; | ||||||
|   sfc.render = (h, context) => |   sfc.render = (h, context) => { | ||||||
|     render(h, context, { |     const inherit = inheritKey.reduce((obj, key) => { | ||||||
|       style: context.data.style, |       if (context.data[key]) { | ||||||
|       class: context.data.class, |         obj[mapInheritKey[key] || key] = context.data[key]; | ||||||
|       staticClass: context.data.staticClass |       } | ||||||
|     }); |       return obj; | ||||||
|  |     }, {}); | ||||||
|  |     return render(h, context, inherit); | ||||||
|  |   }; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| export default name => (sfc, isFunctional) => { | export default name => (sfc, isFunctional) => { | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user