我的问题是我的 swiper 不显示图像

问题描述

我正在使用 react-native-swiper-flatlist.Swiper 和来自 swiper 的点在那里,但没有显示图像。我对本机反应很陌生。这是我的代码

<SwiperFlatList
          autoplay
          autoplayDelay={2}
          autoplayLoop
          index={2}
          showPagination
          data={img}
          renderItem={({ item }) =>{
            return(
              <Image style={{width,height: 200,backgroundColor:"#f0ffff" }} source={{uri:item.uri}}/>
            )
          } }
        />

解决方法

  • 首先尝试将您的 SwiperFlatList 保持在 View Component & Style 中,应为 flex:1。
  • 仔细检查您的数据格式是什么以及如何在图像中呈现。

否则请分享完整的源代码。

您的图像数据不是来自网络,这是本地数据,因此请使用此代码:

<Image style={{width,height: 300,backgroundColor:"#f0ffff",flex: 1 }} source={item.uri}/>

代替

<Image style={{width,flex: 1 }} source={{uri:item.uri}}/>

还要更改数据格式:

const img=[
    {uri:'../../assets/image.png',key: '1'},{uri:'../../assets/image.png',key: '2'},key: '3'}
  ];

const img=[
    {uri:require('../../assets/image.png'),{uri:require('../../assets/image.png'),key: '3'}
  ];

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...