React之state
,props
,refs
。
state
- state(状态):是组件最重要的属性。用来存放数据。对象格式。
- 组件通过更新state的中的数据进行页面显示的更新。
- state中的数据只能通过setState()进行更新。
props
每个组件对象都会有props
一般是类式组件使用。函数式组件也可以用。
1 | function app(props){ |
props
一般用来组件间传值。可参考:
*constructor
是否用到constructor,取决于你有没有这种需求:
在构造器中通过this引用props
1 | class demo extends Component{ |
一般用不到。
refs
用来方便获取dom
元素。
字符串形式(不推荐)
1 | class demo extends Component{ |
回调函数形式
1 | class demo extends Component{ |
createRef API
1 | class demo extends Component{ |
- 本文链接: https://anyway521.gitee.io/post/dcf48b9f.html
- 最后更新:
- 版权声明: 博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议进行许可,转载请注明出处!