react hooks img 显示默认图片
图片不存在或者路径不存在
import defaultImg from "./default.jpg";
const { picUrl} = props.item;
const [imgSrc, handleImageErrored] = useState(picUrl);
<img onError={() => handleImageErrored(defaultImg)} src={imgSrc} />
图片不存在或者路径不存在
import defaultImg from "./default.jpg";
const { picUrl} = props.item;
const [imgSrc, handleImageErrored] = useState(picUrl);
<img onError={() => handleImageErrored(defaultImg)} src={imgSrc} />