2016-12-06 57 views
0

我有一個React SimpleImage component它使用srcSet來使用img上的srcset屬性。srcset不能在img

該組件具有的代碼:

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. 

回答

0

使用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="[* + *]" 
> 

More info in the react docs.

+0

我在組件中使用了'srcSet',生成的標記中的'srcset'屬性導致isssue:https://github.com/vamsiampolu/css-in-js-test/blob/glamor/app/SimpleImage。 JS – vamsiampolu