[英]Is there a way to lazyload the image in CardMedia component in material ui?
我正在嘗試延遲加載 CardMedia 組件中的圖像。 是否有我可以使用的屬性或任何其他方式將圖像的延遲加載合並到組件中。
<CardMedia
key={cardIndex}
component="img"
style={{objectFit: 'contain', height: props.height}}
image={(cardItem)}
/>
幸運的是,是的。 一旦你添加了component="img"
屬性,你就可以在組件中訪問loading
屬性。 將其設置為loading='lazy'
,您就可以使用 go。
<CardMedia key={cardIndex} component="img" loading="lazy" image="{(cardItem)} />
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.