赞
踩
state 和 props 主要的区别在于 props 是不可变的,而 state 可以根据与用户交互来改变。这就是为什么有些容器组件需要定义 state 来更新和修改数据。 而子组件只能通过 props 来传递数据。
class MyComponent extends React.Component {
//此处的构造器是可以省略的
constructor(props){
super(props);
}
render() {
return <div>此处获得了siteName的值 {
this.props.siteName}</div>;
}
}
var element = <MyComponent siteName=
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。