问题
When I have the srcset
property on my <img />
tag, why doesn't it show up in the browser? It appears as through React.js is stripping it out.
<img src="/images/logo.png" srcset="/images/logo-1.5x.png 1.5x, /images/logo-2x.png 2x" />
回答1:
The solution is to use srcSet
instead of srcset
.
<img src="/images/logo.png" srcSet="/images/logo-1.5x.png 1.5x, /images/logo-2x.png 2x" />
Reference: https://facebook.github.io/react/docs/tags-and-attributes.html under HTML Attributes
回答2:
Another ugly solution using template literals:
<img
alt=''
src={require('../../assets/images/logo/logo.png')}
srcSet={`
${require('../../assets/images/logo/logo@2x.png')} 2x,
${require('../../assets/images/logo/logo@3x.png')} 3x
`}
/>
来源:https://stackoverflow.com/questions/34695899/why-is-react-js-removing-the-srcset-tag-on-img