为什么我收到这个警告?
警告:img元素必须有一个alt prop,要么是有意义的文本,要么是空字符串用于装饰图像jsx-a11y/img-has-alt
它显示第13行,但没有任何道具使用.
Bar*_*mar 13
这意味着当您在HTML中创建图像时,应该包含一个alt
属性,以使屏幕阅读器和文本浏览器受益.
<img src="url" alt="description of image">
Run Code Online (Sandbox Code Playgroud)
我有同样的错误。基本上,您不应该在alt
属性中包含这些词。image or picture, or photo
// avoid using image or picture, or photo
// do
<img src="foo" alt="nice"/>. // good
// don't
<img src="foo" alt="foo is coming "/>. // bad
Run Code Online (Sandbox Code Playgroud)
这意味着您的<img>
标记必须在其alt
上具有如下属性:
<img src="pathToYourImage.extension" alt="My Awesome Image">
如果未加载图像,alt
则将显示属性内的文本。
我对这段代码有类似的错误。
<img src={props.contacts.imgUrl}/>
Run Code Online (Sandbox Code Playgroud)
解决方案:注意弯曲括号外的图像锚上的 alt= 位置
<img src={props.contacts.imgUrl} alt=""/>
Run Code Online (Sandbox Code Playgroud)
小智 6
这意味着你的图像需要一个描述,这是img 标签中名为alt的属性,所以只要你在 JSX 和 React 中编写就使用它:
<img src={ImageImported} alt="description of image"/>
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
21509 次 |
最近记录: |