gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 20:33:53 25 4
gpt4 key购买 nike

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com