``` /** * 找不到 | 加载失败使用默认图片 * @param props */ export function ImageElement(props: {w: string, h: string, src: string | undefined}): React.ReactElement { const [url, setUrl] = useState<string>('/默认图片路径.png'); useEffect(() => { const img: HTMLImageElement = new Image(); img.src = props.src || ''; img.onload = () => { setUrl(img.src) } img.onerror = () => { // console.log('错误') } }, [props]); return ( <img alt='' {...props} src={url}/> ) } ``` 使用方式 `<ImageElement w='100px' h='100px' src='xxxxxx'/>`