场景
最近在做多模态智能搜索功能,里面的以文搜文和以图搜图都有瀑布流的展示,多年前做的瀑布流忘记用的啥了,把这次使用的记录一下吧。
1.安装vue-waterfall-plugin
npm install vue-waterfall-plugin --save
2.vue文件中引入
import { LazyImg, Waterfall } from 'vue-waterfall-plugin'
import 'vue-waterfall-plugin/dist/style.css'
export default {
components: {Waterfall, LazyImg},
...
}
3.在所需的位置使用瀑布流插件
<div class="picContent">
<Waterfall :list="picData" :gutter="20" :width="246" v-if="picData&&picData.length>0">
<template #item="{ item }">
<div class="pic__card" @click="showEntityInfo(item)" :style="checkedEntity.eid==item.eid?'border-color:#427DFF':''">
<LazyImg :url="item.location_url" :key="item.eid"/>
</div>
</template>
</Waterfall>
<div class="picListEmpty" v-else>
<img class="empty_search" src="@/assets/images/empty_search.png">
</div>
</div>
该例子的picData格式如下(当然也可以是普通的一维数组,不一定非要是类数组对象):
picData: [
{
location_url: '图片地址',
eid: '唯一标识'
}
]
这样瀑布流图片就显示出来啦,嘻嘻,今天是程序员节所以才发博客的。
vue-waterfall-plugin的github地址如下:
vue2和3的版本都有
https://github.com/heikaimu/vue-waterfall-plugin