思路
1.首先定义一个瀑布流容器,它的高度暂定(后面会更新)。把需要布局的组件(这里叫做waterfall-item)放在瀑布流容器里面渲染出来。使用绝对定位(position: absolute),把它移到屏幕外面,不要占用页面高度,并且设置不可见(visibility:hidden)。
<div class="waterfall-container" ref="waterfallWrapper" :style="{ height: wrapperHeight + 'px' }">
<div
v-for="(post, index) in posts"
:key="post.title"
class="waterfall-item"
>
<div class="waterfall-card">
<PostCard
:title="post.title"
:content="post.excerpt"
:time="new Date(post.date).toLocaleDateString()"
:tag="post.tags ? post.tags.join(', ') :