技术栈:vue3
实现背景:最近项目不忙,想拿掘金文章联系一些小demo,分享一个小菜鸡的踩坑历程!!
借鉴文章:借鉴是雅称,俗称叫照葫芦画瓢加上一些自己的理解!!
借鉴地址:https://juejin.cn/post/7322655035699396660
实现过程:
思想:外层盒子使用绝对定位,里层每单个盒子使用相对定位,第一行正常排列,第二行排在第二行高度最小的下方
资源:小红书network在网络模块搜索:homefeed接口
一:将接口数据分别定义在public文件里面data.json,使用fetch请求public文件

- 我们看看如果实现这个方式需要什么参数:1.原始数据:接口请求过来的数据carList:[]
- 2.我们每次都需要对比上一行的高度所以需要把上一行的高度全部存起来,多少个???暂定为可传参数column,将上一行高度放在一个数组里面columnHeight: new Array(props.column).fill(0)
- 我们是使用平移的css实现方式,需要知道每个盒子的宽高以及平移的x,y。。。。cardPos: []
- 我们需要给盒子定宽度itemWidth: 0,每个盒子的宽度是一定的,
- 再就是列表查询参数,page:1,isFinish: false,(是否是最后一页)
二:接下来看看css,html的怎么实现
tip:记得加入box-sizing:border-box!!!
三 :生命周期初始化
computedCardPos函数
获取最小高度以及最小高度的坐标是我们经常需要可以放到computed里面计算

父组件里面我们定义插槽出口


const colorArr = ["#409eff", "#67c23a", "#e6a23c", "#f56c6c", "#909399"];
从父组件传来的column我们还没有解决!!!!
父组件:
子组件:


