我有一个反应SimpleImage元件,它使用srcSet在img上使用srcset属性。
该组件具有以下代码:
const image = (<img
{...imageStyle}
src={src}
srcSet={srcsetStr}
alt={alt}
width={width}
height={height}
role="presentation"
onLoad={onLoad}
onError={onFail}
/>);图像被放置在div中。
return (<div {...wrapperStyle}>
{statusIndicator}
{image}
</div>);wrapperStyle被定义为:
const mainWrapperStyle = style({
backgroundColor: 'white',
backgroundSize: 'contain',
backgroundRepeat: 'none',
boxSizing: 'border-box',
position: 'relative',
width,
height,
}div上的宽度与img上的宽度相同。
在生成的标记的srcsert属性中有一个错误,如下所示:
<img
srcset=" https://webkit.org/demos/srcset/image-src.png 1x
https://webkit.org/demos/srcset/image-2x.png 2x
https://webkit.org/demos/srcset/image-3x.png 3x
https://webkit.org/demos/srcset/image-4x.png 4x" width="800px"
height="800px" role="presentation"
src="https://webkit.org/demos/srcset/image-src.png"
data-css-44fijj="[* + *]"
>我在这里有个错误:
DOMPropertyOperations.js?17f3:142 Failed parsing 'srcset' attribute value since it has an unknown descriptor.发布于 2016-12-06 16:45:29
使用srcSet而不是srcset
<img
srcSet=" https://webkit.org/demos/srcset/image-src.png 1x
https://webkit.org/demos/srcset/image-2x.png 2x
https://webkit.org/demos/srcset/image-3x.png 3x
https://webkit.org/demos/srcset/image-4x.png 4x" width="800px"
height="800px" role="presentation"
src="https://webkit.org/demos/srcset/image-src.png"
data-css-44fijj="[* + *]"
>发布于 2022-08-08 18:57:51
import meal1x from '../images/meal.jpg';
import meal2x from '../images/meal@2x.jpg';
import meal3x from '../images/meal@3x.jpg';
<img
className='meal'
src={meal1x}
srcSet={`${meal1x} 1x, ${meal2x} 2x, ${meal3x} 3x`}
/>https://stackoverflow.com/questions/40998320
复制相似问题