vue 瀑布流布局 复制即用

server/2024/9/23 3:21:44/

插件 npm install vue-waterfall-plugin-next 或者 yarn add vue-waterfall-plugin-next

点击vue-waterfall-plugin-next进入文档

组件

<template><Waterfall :lazyload="false" :breakpoints="breakpoints" :gutter="8" :list="list" :column-count="3"><template #item="{ item }"><div class="card_content"><div class="card_img" :class="{ active: !item.goodsPicture && !item.storePicture }"><LazyImg class="cover" :url="item.src" /></div><div>title</div></div></template></Waterfall>
</template><script setup>
import { computed, ref } from 'vue'
import { LazyImg, Waterfall } from 'vue-waterfall-plugin-next'
import 'vue-waterfall-plugin-next/dist/style.css'
const props = defineProps({productList: {type: Array}
})const list = computed(() => {return props.productList
})
const breakpoints = ref({3000: {//当屏幕宽度小于等于3000rowPerView: 8, // 一行8图},1800: {//当屏幕宽度小于等于1800rowPerView: 6,// 一行6图},1200: {//当屏幕宽度小于等于1200rowPerView: 4,},500: {//当屏幕宽度小于等于500rowPerView: 2,},
})</script><style lang="scss" scoped>
.card_content {border-radius: 4px;background: #fff;box-sizing: border-box;.card_img {margin-bottom: 7px;&.active {border: 1px solid #e7e7e7;}:deep(.lazy__img) {width: 100%;border-radius: 4px;font-size: 0;height: 100%;}}.content {padding: 0 8px;.store {color: rgba(0, 0, 0, 0.4);font-size: 12px;font-weight: 400;margin-bottom: 4px;}.title {font-size: 16px;font-weight: 500;margin-bottom: 14px;}.tags {display: flex;flex-wrap: wrap;.tags-item {background: rgba(153, 151, 255, 0.05);border-radius: 2px;padding: 3px 4px;margin: 0 5px 5px 0;color: rgba(0, 0, 0, 0.4);font-size: 12px;border: 1px solid rgb(244, 244, 249);&:last-child {margin-right: 0;}}}}
}
</style>

使用组件

// 父组件index.vue
<template><div class="container" id="main"><productCard :productList="productList"></productCard><div class="loading-text" v-if="loading">加载中...</div><div class="loading-text" v-if="finish">没有更多了</div></div>
</template>
<script setup>
import productCard from './components/index.vue'
const loading = ref(false)
const finish = ref(false)
let arr = [{id: 1,src: 'https://img.beiqiai.com/img1.jpg'},{id: 2,src: 'https://img.beiqiai.com/img2.jpg'},{id: 3,src: 'https://img.beiqiai.com/img3.jpg'},{id: 4,src: 'https://img.beiqiai.com/img4.jpg'},{id: 5,src: 'https://img.beiqiai.com/img5.jpg'},{id: 6,src: 'https://img.beiqiai.com/img6.jpg'},{id: 7,src: 'https://img.beiqiai.com/img7.jpg'},{id: 8,src: 'https://img.beiqiai.com/img8.jpg'},{id: 9,src: 'https://img.beiqiai.com/img9.jpg'},{id: 10,src: 'https://img.beiqiai.com/img10.jpg'},{id: 11,src: 'https://img.beiqiai.com/img11.jpg'},{id: 12,src: 'https://img.beiqiai.com/img12.jpg'},{id: 13,src: 'https://img.beiqiai.com/img13.jpg'},{id: 14,src: 'https://img.beiqiai.com/img14.jpg'},{id: 15,src: 'https://img.beiqiai.com/img15.jpg'},{id: 16,src: 'https://img.beiqiai.com/img16.jpg'},{id: 17,src: 'https://img.beiqiai.com/img17.jpg'},{id: 18,src: 'https://img.beiqiai.com/img18.jpg'},{id: 19,src: 'https://img.beiqiai.com/img19.jpg'},{id: 20,src: 'https://img.beiqiai.com/img20.jpg'},{id: 21,src: 'https://img.beiqiai.com/img21.jpg'},{id: 22,src: 'https://img.beiqiai.com/img22.jpg'},{id: 23,src: 'https://img.beiqiai.com/img23.jpg'},{id: 24,src: 'https://img.beiqiai.com/img24.jpg'},{id: 25,src: 'https://img.beiqiai.com/img25.jpg'}]let productList = ref([{id: 1,src: 'https://img.beiqiai.com/img1.jpg'},{id: 2,src: 'https://img.beiqiai.com/img2.jpg'},{id: 3,src: 'https://img.beiqiai.com/img3.jpg'},{id: 4,src: 'https://img.beiqiai.com/img4.jpg'},{id: 5,src: 'https://img.beiqiai.com/img5.jpg'},{id: 6,src: 'https://img.beiqiai.com/img6.jpg'},{id: 7,src: 'https://img.beiqiai.com/img7.jpg'},{id: 8,src: 'https://img.beiqiai.com/img8.jpg'},{id: 9,src: 'https://img.beiqiai.com/img9.jpg'},{id: 10,src: 'https://img.beiqiai.com/img10.jpg'},{id: 11,src: 'https://img.beiqiai.com/img11.jpg'},{id: 12,src: 'https://img.beiqiai.com/img12.jpg'},{id: 13,src: 'https://img.beiqiai.com/img13.jpg'},{id: 14,src: 'https://img.beiqiai.com/img14.jpg'},{id: 15,src: 'https://img.beiqiai.com/img15.jpg'},{id: 16,src: 'https://img.beiqiai.com/img16.jpg'},{id: 17,src: 'https://img.beiqiai.com/img17.jpg'},{id: 18,src: 'https://img.beiqiai.com/img18.jpg'},{id: 19,src: 'https://img.beiqiai.com/img19.jpg'},{id: 20,src: 'https://img.beiqiai.com/img20.jpg'},{id: 21,src: 'https://img.beiqiai.com/img21.jpg'},{id: 22,src: 'https://img.beiqiai.com/img22.jpg'},{id: 23,src: 'https://img.beiqiai.com/img23.jpg'},{id: 24,src: 'https://img.beiqiai.com/img24.jpg'},{id: 25,src: 'https://img.beiqiai.com/img25.jpg'}])//获取接口数据
const getProduct = () => {loading.value = trueproductList.value = [...productList.value, ...arr]
}
const handleScroll = () => {const scrollHeight = Math.max(document.documentElement.scrollHeight, document.body.scrollHeight)//滚动条滚动距离const scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop//窗口可视范围高度const clientHeight =window.innerHeight || Math.min(document.documentElement.clientHeight, document.body.clientHeight)if ((clientHeight + scrollTop) + 100 >= scrollHeight) {//快到底时----加载getProduct()}
}const debounce = (fn, delay) => {let timeoutreturn function () {clearTimeout(timeout)timeout = setTimeout(() => {fn.apply(this, arguments)}, delay)}
}
onMounted(() => {window.addEventListener('scroll', debounce(handleScroll, 1000))
})</script><style lang="scss" scoped>
.loading-text {text-align: center;position: absolute;left: 0;right: 0;z-index: 999;margin: auto;padding: 20px 0;font-size: 16px;
}:deep(.waterfall-list) {background: none;
}.container {padding: 0 12px;
}
</style>

http://www.ppmy.cn/server/13954.html

相关文章

【零基础入门TypeScript】环境

目录 定义环境 句法 例子 环境声明是告诉 TypeScript 编译器实际源代码存在于其他地方的一种方式。当您使用大量第三方js库&#xff08;如 jquery/angularjs/nodejs&#xff09;时&#xff0c;您无法在 TypeScript 中重写它。对于 TypeScript 程序员来说&#xff0c;在使用这…

中国航天日特辑 | PARASOFT——从NASA JPL到航空航天的星辰大海

4月24日&#xff0c;是中国航天日&#xff08;Space Day of China&#xff09;&#xff0c;一个庆祝和纪念中国航天事业成就的特殊时刻。在这一天&#xff0c;我们不仅仅是赞颂那些辉煌的航天成就&#xff0c;还要探讨那些为航天事业做出重大贡献的合作伙伴和技术解决方案提供者…

BUUCTF---misc---[SWPU2019]我有一只马里奥

1、下载附件是一个.exe文件 2、运行之后可以看到桌面生成了1.txt文件&#xff0c;文件里面有如下内容 3、经过信息搜索&#xff1a;NTFS&#xff08;New Technology File System&#xff09;是一种由Microsoft开发的专有日志文件系统。根据它的提示&#xff0c;应该是把flag.tx…

【七】jmeter5.5+influxdb2.0+prometheus+grafana

参考文章&#xff1a;https://blog.csdn.net/wenxingchen/article/details/126892890 https://blog.csdn.net/Zuo19960127/article/details/119726652 https://blog.csdn.net/shnu_cdk/article/details/132182858 promethus参考 由于自己下载的是infuldb2.0&#xff0c;所以按照…

Android 12 如何加载 native 原生库

在 Android 7.0 及更高版本中&#xff0c;系统库与应用库是分开的。 图1. 原生库的命名空间 原生库的命名空间可防止应用使用私有平台的原生 API&#xff08;例如使用 OpenSSL&#xff09;。该命名空间还可以避免应用意外使用平台库&#xff08;而非它们自己的库&#xff09;的…

JavaEE初阶之IO流快速顿悟一(超详细)

目录 题外话 正题 IO流 Java.io.FileInputStream int read() int read(byte[] b) 关于异常 Java7的新特性: try-with-resources ( 资源自动关闭) Java.io.FileOutputStream void write(int b) void write(byte[] b) 小结 题外话 十年青铜无人问,一朝顿悟冲王者 前天…

你们项目日志是如何处理的???

ELK日志采集系统 1.什么是ELK ELK 是一套流行的数据搜索、分析和可视化解决方案&#xff0c;由三个开源项目组成&#xff0c;每个项目的首字母合起来形成了“ELK”这一术语&#xff1a; Elasticsearch (ES): Elasticsearch 是一个基于 Apache Lucene 构建的分布式、实时搜索与…

RUST腐蚀服务器添加 TAGS标签教程

RUST腐蚀服务器添加 TAGS标签教程 大家好我是艾西&#xff0c;一个做服务器租用的网络架构师。我们自己搭建架设的服务器在steam展示面板看到跟别人的不一样是咋回事&#xff1f; 这个其实就是服务器的一个标签&#xff0c;那么主要的作用就是让大家在选择服务器时更快更直接的…