Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.1k views
in Technique[技术] by (71.8m points)

一个奇怪的js语法格式问题

return <span {...{attrs: attributes}}>{children}</span>

这种是什么写法?第一次看见,我把他输出来,里面长这样

image.png


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

JSX 可以看下 React 官网的文档 JSX 简介

{...{attrs: attributes}} 这个相当于把 attrs 对象展开了

{children} 的话调用这个子组件的时候可以往里传东西,比如传个 button 的话,最后就是 span 套 button 了

好像还有 typescript,attributes是个 interface,对 attrs 进行了定义


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...