首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >当我使用renderItme时,react-native-snap-carousel返回"Cannot read property 'concat‘of undefined“

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

Stack Overflow用户
提问于 2019-06-20 14:03:15
回答 1查看 550关注 0票数 0

我正在学习React-Native,并在我的项目中使用react-native-snap-carousel。我想显示一些图像,但是我得到了错误的Cannot read property 'concat' of undefined

这是我的代码。

代码语言:javascript
复制
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>
   )

}

如果我改变了

代码语言:javascript
复制
          <View>
                <Image source={require(item)}></Image>
            </View>

代码语言:javascript
复制
          <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.
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-06-20 14:40:36

你试过这个吗?

代码语言:javascript
复制
let imageList = [require('../images/index-bg.png'), require('../images/down.png')];

然后

代码语言:javascript
复制
  <View>
    <Image source={item}></Image>
  </View>

RN中的镜像所需的源必须在运行前定义

如果有效,请让我知道!

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56679869

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档