Javascript 反应-消耗阵列反应axios

Javascript 反应-消耗阵列反应axios,javascript,json,reactjs,es6-promise,axios,Javascript,Json,Reactjs,Es6 Promise,Axios,我试图使用带有react的轴来使用json,但我无法使用它获取图像的url,其余的作为id和标题。但是图像和用户,我不能 您好,我正在尝试使用json,使用带有react的axios,但是我无法使用它获取图像的url,其余的作为id和标题。但是图像和用户,我不能 我的代码: 从“React”导入React 导出默认道具=>{ const renderRows=()=>{ const list=props.list | |[] 返回列表.map(快照=>( {shots.title} {shot

我试图使用带有react的轴来使用json,但我无法使用它获取图像的url,其余的作为id和标题。但是图像和用户,我不能

您好,我正在尝试使用json,使用带有react的axios,但是我无法使用它获取图像的url,其余的作为id和标题。但是图像和用户,我不能

我的代码:

从“React”导入React
导出默认道具=>{
const renderRows=()=>{
const list=props.list | |[]
返回列表.map(快照=>(
{shots.title}

{shots.views_count}

{shots.description}

{/* */} )) } 返回( {renderRows()} ) }

您不需要在image src属性上使用引号

我还会将地图简化为类似的内容:

export default myComponent = ({ list }) => {

  const listItems = list.map(shots => (
    <div key={shots.id}>
       <p>{shots.title}</p>
       <p>{shots.views_count}</p>
       <p>{shots.description}</p>
       <img src={shots.images.normal} />
    </div>
  );

  return (
    <div>
      {listItems}
    </div>
  );
}
导出默认myComponent=({list})=>{
const listItems=list.map(快照=>(
{shots.title}

{shots.views_count}

{shots.description}

); 返回( {listItems} ); }
与组件当前的使用方式类似,使用方式类似于

编辑:

您的数据源可能没有强架构,也可能没有每个条目的映像。因此,在这种情况下,请尝试用以下内容替换部分:

return list.map(shots => {
  var imageSrc = (shots.images) ? shots.images.normal : null;
  return (
    <div key={shots.id}>
        <p>{shots.title}</p>
        <p>{shots.views_count}</p>
        <p>{shots.description}</p>
        <img src={imageSrc} alt="" />
    </div>
  )
})
returnlist.map(快照=>{
var imageSrc=(shots.images)?shots.images.normal:null;
返回(
{shots.title}

{shots.views_count}

{shots.description}

) })
为什么
{}
并注释掉了?你看不出这一行与其他行有多大的不同吗?我不想问问题就注释了。因此,你发布的代码不是你有问题的代码?我有问题的是代码。是的,你注释掉了img,因此它不会显示我已经更改了,它不起作用。显示错误:uncagught(承诺中)TypeError:无法读取renderRows(app.js:31738)的app.js:31757 at Array.map()处未定义的属性'normal',exports.default(app.js:31765)的无状态组件.render(app.js:23797)的app.js:24548处的属性'normal'(app.js:23828)在ReactCompositeComponentWrapper.\u RenderValidatedComponentWithoutownerContext(app.js:24547)在ReactCompositeComponentWrapper.\u renderValidatedComponent我们需要查看您使用
更改的代码,然后可能
列表
传递到
myComponent
不是您所说的,它现在不会在屏幕上显示任何内容:/。我想我必须执行for之类的操作才能获得api的图像URL