首页 > 解决方案 > 在带有外部链接的地图函数中动态渲染 React Native 图像

问题描述

let result = this.state.yards.map( yard=> {
         return <View><Text style={{color:'black'}}><Text style= 
{{color:'darkslateblue', fontSize:18}}>{yard.name}</Text>{"\n"}{yard.coordinates}  {yard.photourl}</Text><Image source={require(yard.photourl)} /></View>
      });

yard.photourl 代表在浏览器中工作的正确 url,但我似乎无法在 this.state.items.map 中动态呈现它

这些链接是公共 aws 链接。

帮助!

标签: imagereact-native

解决方案


根据 React Native文档,网络图像使用以下语法加载:

<Image source={{uri: 'https://facebook.github.io/react/logo-og.png'}} style={{width: 400, height: 400}} />

请注意,您需要手动指定图像大小。


推荐阅读