SVG图片未显示在本机反应中

时间:2021-06-20 01:02:49

标签: javascript reactjs react-native svg react-hooks

有人能帮我理解为什么这个 svg 没有渲染到我的屏幕上吗?

  const fireee = this.state.h.map(e => { 
          <SvgUri
    width="10%"
    height="10%"
    uri="https://s3.us-east-2.amazonaws.com/nomics-api/static/images/currencies/btc.svg"
  /> }
      )

      return (    

<View>
{fireee}
</View>

2 个答案:

答案 0 :(得分:0)

试试这个:

<View>
  <SvgUri
    width="10%"
    height="10%"
    source={{ uri: "https://s3.us-east-2.amazonaws.com/nomics-api/static/images/currencies/btc.svg"}} 
  />
</View>

答案 1 :(得分:0)

const fireee = this.state.h.map((e) => {
      if (e.logo_url.includes('svg')) {
        console.log(e.logo_url);
        return (
          <SvgUri
    width="3%"
    height="3%"
    
    uri={e.logo_url}/>
        );
      } else {
        return (
           <Image
            source={{ uri: e.logo_url }}
            style={{ width: 20, height: 20, left: '20%' }}
          />
        )
      }
    });

需要创建一个条件来对待 svg 和 png 不同