React - 如何将两个属性绑定到一个 img 标签
React - how to bind two attributes to one img tag
我想将 src & width 属性添加到 <img>
标签中。我使用了以下代码:
<img src={ p.productImgUrl }{ (p.bottleSize==='small' ? '"width=100px"' : '')} />
错误如下:
Error: Unexpected token
您可以使用内联样式设置高度和宽度,如下所示
<img
src={ p.productImgUrl }
style={ p.bottleSize==='small' ? {width:'100px'} : {} } />
或使用 width attribute
<img
src={ p.productImgUrl }
width={ p.bottleSize==='small' ? '100px' : '' } />
我想将 src & width 属性添加到 <img>
标签中。我使用了以下代码:
<img src={ p.productImgUrl }{ (p.bottleSize==='small' ? '"width=100px"' : '')} />
错误如下:
Error: Unexpected token
您可以使用内联样式设置高度和宽度,如下所示
<img
src={ p.productImgUrl }
style={ p.bottleSize==='small' ? {width:'100px'} : {} } />
或使用 width attribute
<img
src={ p.productImgUrl }
width={ p.bottleSize==='small' ? '100px' : '' } />