react设置默认state和默认props
2024-08-27 19:02:54
1.默认状态设置
1.constructor (ES6)
constructor(props) {
this.state = {
n: ...
}
}
2.getInitialState (ES5)
只能用在React.createClass中,extends React.Component不行
2.默认props设置
1.组件外部 (ES6)
component.defaultProps = {
name: '...'
}
2.组件内部 (ES7,必须开启ES7的babel支持)
static defaultProps = {
name: '...'
}
3. getDefaultProps (ES5)
只能用在React.createClass中,extends React.Component不行
最新文章
- 关于C#消息调度(作业日志)
- 【Spring】非Spring IOC容器下获取Spring IOC上下文的环境
- C++调用约定和名字约定
- MySQL Workbench “Error Code: 1175” 的解决方法
- win7远程桌面恢复全屏状态快捷键
- [XAF] How to use the Allow/Deny permissions policy in the existing project
- [SoapUI] 同一个Resource不同参数时,在两个step里默认打开总是同一个Resource
- iOS常用宏 定义
- 高效的两段式循环缓冲区──BipBuffer
- 【关于HBITMAP, DC, MEM DC, Clipboard】将HBITMAP拷贝到Clipboard(Windows Clipboard &; OLE Clipboard)
- <;mvc:annotation-driven />;
- 简易nagios安装
- (Problem 62)Cubic permutations(待续)
- 配置python+mod_wsgi+apache 时 在浏览器中访问服务器时报错:Invalid HTTP_HOST header: &#39;XXXXX&#39;. You may need to add u&#39;XXXXX&#39; to ALLOWED_HOSTS,在setting.py中添加‘*”无效的原因
- linux_rsync定时备份
- 16进制转化8进制---map
- 如何从零开始系统化学习视觉SLAM?
- leetcode-1-TwoNums
- 设计模式之Prototype
- windows命令启动mysql