我正在尝试为我的 react-native 项目创建一个图像 slider ,但我真的不知道为什么它一直向我发送此错误:ReferenceError: Can't find variable: props,当我有以下构造函数时,并渲染;
constructor(props){
super(props)
this.state = {
imagesSlider: [
require('../images/1.jpg'),
require('../images/2.jpg')
]
}
}
render() {
return (
<Swiper style={styles.slide} autoplay> {
this.state.imagesSlider.map(function(item,i){
<View key={i}>
<Image source={props.item}/>
</View>
})
}
</Swiper>
);
}
最佳答案
您应该使用“this”引用您的 Prop 和状态变量。所以在你的它应该改为:
<Image source={this.props.item}/>
关于image - 找不到变量 : props (react-native),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47738093/