Open chengfengjie opened 6 years ago
style
所有核心组件接收名为style的属性,传入对象,所用css采用驼峰规则,实际开发中建议采用StyleSheet.create来几种定义组件样式
const styles = StyleSheet.create({
bigblue: {
color: 'blue',
fontWeight: 'bold',
fontSize: 30,
},
red: {
color: 'red',
}
})
指定宽高
style
中的width
和height
属性用于控制组件的宽度和高度,是与设备像素无关的逻辑像素点
初始化项目
属性
props
所有组件可以在标签中传入属性,如下代码传入名称为name,值为'Rexxar'的属性
组件内部用
this.props.propName
获取属性,属性一经指定,就不能更改,如果需要更改,需要用State
状态State(状态)
在constructor中初始化state,在需要的地方调用
setState
方法修改值,初始化和修改代码如下: