React入门教程(三)—— this.props
2016-03-22 15:47
549 查看
this.props
React允许将代码封装成组件,然后像插入普通 HTML 标签一样,在网页中插入这个组件。
组件的用法与原生的 HTML 标签完全一致,可以任意加入属性,比如
React允许将代码封装成组件,然后像插入普通 HTML 标签一样,在网页中插入这个组件。
//定义一个名为Hello的组件 //用方法React.createClass来创建一个组件 var Hello = React.createClass({ //每一个组件中必须有一个render方法,用于输出组件 render: function() { //使用return来返回要输出的内容 return <h1>Hello {this.props.name}</h1>; } }); ReactDOM.render( //插入模板<Hello />时,会生成Hello的一个实例,组件类的第一个字母必须大写 <Hello name="wang" />, document.getElementById('example') );
组件的用法与原生的 HTML 标签完全一致,可以任意加入属性,比如
<Hello name="wang">,就是
Hello组件加入一个
name属性,值为
wang。组件的属性可以在组件类的
this.props对象上获取,比如
name属性就可以通过
this.props.name读取。
相关文章推荐
- iOS原生项目中集成React Native
- React Native学习笔记-1:JSC profiler is not supported.
- React Native 红屏之Could not connect to development server.
- react-redux
- React Native中常见操作
- react-lifecycle-parent-child.jsx(自github)
- react-router
- React Native 开发笔记
- React-Native入门指导之iOS篇
- React-周边类库
- React入门教程(二)
- 使用React并做一个简单的to-do-list
- React-服务器端渲染
- ReactNative 代码智能提醒(webstorm)
- React-性能优化详解
- React-动画详解
- React Native学习笔记-1:JSC profiler is not supported.(转载)
- React.js入门必须知道的那些事
- React Native: 把现代web科技带给移动开发者
- [转] 三步将你的 React Native 项目运行在 Web 浏览器上面