react学习12

编程入门 行业动态 更新时间:2024-10-10 08:24:03

<a href=https://www.elefans.com/category/jswz/34/1771383.html style=react学习12"/>

react学习12

组件属性的延展操作

  • 组件标签传递属性时可以借助对象的延展操作,一次性把所有的属性添加进去
import React from 'react'class Test extends React.Component {render () {return (<div><div>{this.props.msg}</div><div>{this.props.info}</div><div>{this.props.abc}</div></div>)}
}class PropsTest extends React.Component {render () {let obj = {msg: 'hi',info: 'coniqiwa',abc: '123'}// 如下的解构表示从obj中单独解构出msg,其余的属性赋值给otherlet {msg, ...other} = objreturn (<div><h1>组件属性的延展操作</h1><hr/><Test msg='hello' info='nihao'/><Test {...obj}/><Test {...other}/></div>)}
}export default PropsTest

更多推荐

react学习12

本文发布于:2024-03-12 19:32:46,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1732246.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:react

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!