gpt4 book ai didi

javascript - 当我使用 renderItme 时,react-native-snap-carousel 返回 "Cannot read property ' concat' of undefined”

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

我正在学习React-Native并在我的项目中使用react-native-snap-carousel。我想显示一些图像,但出现错误无法读取未定义的属性“concat”

这是我的代码。

const HomePage = (props) => {
let imageList = ['../images/index-bg.png', '../images/down.png'];

const renderImage = ({ item, index }) => {
return (
<View>
<Image source={require(item)}></Image>
</View>
)
};

return (
<View>
<Carousel
loop={true}
autoplay={true}
data={imageList}
renderItem={renderImage}
sliderWidth={pxToDp(50)}
itemWidth={pxToDp(100)}
/>

</View>
)

}

如果我改变

          <View>
<Image source={require(item)}></Image>
</View>

          <View>
<Image source={'../images/index-bg.png'}></Image>
</View>
···
it works well


I expect it would work like [Usage](https://github.com/archriss/react-native-snap-carousel) but it doesn't work.

最佳答案

你尝试过这个吗?

let imageList = [require('../images/index-bg.png'), require('../images/down.png')];

然后

  <View>
<Image source={item}></Image>
</View>

必须在运行时之前定义 RN 中图像所需的源

让我知道它是否有效!

关于javascript - 当我使用 renderItme 时,react-native-snap-carousel 返回 "Cannot read property ' concat' of undefined”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56679869/

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