image - 找不到变量 : props (react-native)

标签 image react-native constructor super swiper.js

我正在尝试为我的 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/

相关文章:

react-native - 使用 react-native-camera,如何访问保存的图片?

c++ - C++中构造函数的初始化顺序

php - 将blob类型图像上传到数据库,我的代码说它正在上传图像但没有存储在数据库中

android - 十亿像素图像 Android 应用

ios - iOS 5 : UIView converted to video and the resulting video is corrupted

java - java中构造函数类型不匹配

c++ - 使用初始化列表时检查传递给构造函数的参数 - C++

JavaScript - 将图像从 URL 保存到本地计算机特定路径?

javascript - 意外的保留字 'await'

javascript - React Native & TextInput : How to get what the use type one by one for Android?