react.js Replace img src onerror

后端 未结 22 3071
北恋
北恋 2020-11-29 00:20

I have a react component that is the detail view from a list.

I am trying to replace the image with a default image if the image does not exist and there is a 404 er

22条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-29 01:17

    Its So Simple

    e.target.onerror = null If Error Image Also Fails to Load jsx

     (e.target.onerror = null, e.target.src = imageErrorSrc)}/>
    

提交回复
热议问题