我正在尝试根据状态设置容器的背景,但它不断向我显示未定义错误bg
constructor(props) {
super(props)
this.state = {
bg:'#fff'
}
}
render(){
return(<View style={styles.container} />)
}
const styles = StyleSheet.create({
container:{
flex: 1,
backgroundColor: this.state.bg,
}
})
Run Code Online (Sandbox Code Playgroud)
小智 6
更改此代码:
return <View style={[styles.container, backgroundColor: this.state.bg]}/>
Run Code Online (Sandbox Code Playgroud)
对于此代码:
return <View style={[styles.container, {backgroundColor: this.state.bg}]}/>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3044 次 |
| 最近记录: |