我用映射了一個數組,該數組呈現了一個縮略圖和一個包含標題、描述、日期等內容的縮略圖上的{背景img}
我能夠在博客上繪制地圖,并正確地呈現這兩個React組件,但是,我注意到在位置為:absolute的頁面/組件加載上有一個小故障。當我把它改成其他東西時,它不會在渲染時出錯。
在CSS中除了position: absolute之外還有其他不會導致渲染出現小故障的東西嗎?我知道使用absolute會導致問題,因為它覆蓋了正常流程:
const Thumbnail = styled.div`
display: flex;
flex-wrap: wrap;
position: relative;
justify-content: center;
`
const Image = styled.div`
display: flex;
flex-wrap: wrap;
position: relative;
display: inline-block;
`
const Tape = styled.div`
background-image: url(/images/PaperTape.png);
background-position: center;
background-repeat: no-repeat;
z-index: 1;
position: absolute;
bottom: 0;
`
const BlogImages = ({ blog, index = 0 }) => {
const handleImageClick = () => {
}
return (
<Image onClick={() => handleImageClick(index)}>
<Thumbnail>
<Link key={index} to={`/blog/${blog.slug}`} target="_blank" rel="noopener noreferrer">
<img className='blog' src={blog.src} alt="BlogImage"/>
<Tape>
<Title>{blog.title}</Title>
<Date>{blog.date}</Date>
<Description>{blog.description}</Description>
</Tape>
</Link>
</Thumbnail>
</Image>
)
}
function BlogMain() {
const [visible, setVisible] = useState(1);
const loadMore = () => {
setVisible((visible) => visible + 1);
};
<Thumbnail>
{blogs && blogs.length > 0 && blogs.slice(0, visible).map((blog, index) => (
<BlogImages key={index} blog={blog} index={index} />
))}
</Thumbnail>
<LoadMore>
{blogs && blogs.length > visible && (
<Button onClick={loadMore}>
<ButtonText>Load more</ButtonText>
</Button>
)}
</LoadMore>
上一篇python 替換一段
下一篇vue data 層級