使用 vue-waterfall2插件 vue 瀑布流

4 篇文章 0 订阅

一、安装 vue-waterfall2`

npm install --save vue-waterfall2

二、在main.js里面引入

import waterfall from 'vue-waterfall2'
Vue.use(waterfall)

目录结构:

waterfall

​ compontens

​ load.vue

​ index.vue

​ index.less


Index.vue



<template>
  <div class="container_water_fall water_content">
    <waterfall :col="col" :data="data" @loadmore="loadmore">
      <template>
        <div class="cell_item" v-for="(item, index) in data" :key="index">
          <img
            v-if="item.img"
            class="cell_item_img"
            :src="item.img"
            alt="加载错误"
          />
          <div class="item-body">
            <div class="item-title">{{ item.title }}</div>
            <div class="item-footer">
              <div class="name">{{ item.user }}</div>
              <div class="like">
                <div class="item_title">¥{{ item.like }}</div>
                <div class="item_sold">已售888件</div>
              </div>
            </div>
          </div>
        </div>
      </template>
    </waterfall>
    <loading :show="loading" />
  </div>
</template>
 
<script>
/*
  注意:
  1.itemWidth需要与gutterWidth一起使用才会生效,否则会进行自适应宽度
  2.使用了waterfall的组件不允许使用scoped,否则样式会有问题
*/
import loading from "./components/load";
export default {
  props: {
    title: String,
  },
  components: {
    loading,
  },
  data() {
    return {
      data: [],
      col: 2,
      loading: false,
      originData: [
        {
          img:
            "https://image.watsons.com.cn//upload/8a316140.png?w=377&h=451&x-oss-process=image/resize,w_1080",
          avatar:
            "https://img.xiaohongshu.com/avatar/5b7d198a7e6e15000155f7c9.jpg@80w_80h_90q_1e_1c_1x.jpg",
          title: "最近浴室新宠,日系神仙好物了解一下~",
          user: "描述呗",
          like: "953",
        },
        {
          img:
            "https://image.watsons.com.cn//upload/083767f0.JPG?w=828&h=620&x-oss-process=image/resize,w_1080",
          avatar:
            "https://img.xiaohongshu.com/avatar/5b7d198a7e6e15000155f7c9.jpg@80w_80h_90q_1e_1c_1x.jpg",
          title: "150元搞定全套护肤品,这些护肤好物必须交出来!",
          user: "迷人的小妖精迷人的小妖精",
          like: "952",
        },
        {
          img:
            "https://image.watsons.com.cn//upload/02a4f38d.jpg?w=1067&h=1067&x-oss-process=image/resize,w_1080",
          avatar:
            "https://img.xiaohongshu.com/avatar/5b7d198a7e6e15000155f7c9.jpg@80w_80h_90q_1e_1c_1x.jpg",
          title: "最近浴室新宠,日系神仙好物了解一下~",
          user: "迷人的小妖精迷人的小妖精",
          like: "953",
        },
        {
          img:
            "https://image.watsons.com.cn//upload/589585c1.jpeg?x-oss-process=image/resize,w_1080",
          avatar:
            "https://img.xiaohongshu.com/avatar/5b7d198a7e6e15000155f7c9.jpg@80w_80h_90q_1e_1c_1x.jpg",
          title: "150元搞定全套护肤品,这些护肤好物必须交出来!",
          user: "迷人的小妖精迷人的小妖精",
          like: "953",
        },
        {
          img:
            "https://image.watsons.com.cn//upload/d862d932.jpg?w=1080&h=1440&x-oss-process=image/resize,w_1080",
          avatar:
            "https://img.xiaohongshu.com/avatar/5b7d198a7e6e15000155f7c9.jpg@80w_80h_90q_1e_1c_1x.jpg",
          title: "最近浴室新宠,日系神仙好物了解一下~",
          user: "迷人的小妖精迷人的小妖精",
          like: "953",
        },
        {
          img:
            "https://image.watsons.com.cn//upload/eb4fb58f.jpg?w=1080&h=1080&x-oss-process=image/resize,w_1080",
          avatar:
            "https://img.xiaohongshu.com/avatar/5b7d198a7e6e15000155f7c9.jpg@80w_80h_90q_1e_1c_1x.jpg",
          title: "150元搞定全套护肤品,这些护肤好物必须交出来!",
          user: "迷人的小妖精迷人的小妖精",
          like: "953",
        },
        {
          img:
            "https://image.watsons.com.cn//upload/71d19462.jpg?x-oss-process=image/resize,w_1080",
          avatar:
            "https://img.xiaohongshu.com/avatar/5b7d198a7e6e15000155f7c9.jpg@80w_80h_90q_1e_1c_1x.jpg",
          title:
            "贵妇级好用的水乳有哪些呢?千万不要去乱尝试贵妇级好用的水乳有哪些呢?",
          user: "迷人的小妖精迷人的小妖精",
          like: "953",
        },
        {
          img:
            "https://image.watsons.com.cn//upload/415f984f.jpeg?w=828&h=1104&x-oss-process=image/resize,w_1080",
          avatar:
            "https://img.xiaohongshu.com/avatar/5b7d198a7e6e15000155f7c9.jpg@80w_80h_90q_1e_1c_1x.jpg",
          title: "千万不要去乱尝试贵妇级好用的水乳有哪些呢?千万不要去乱尝试",
          user: "迷人的小妖精迷人的小妖精",
          like: "953",
        },
        {
          img:
            "https://image.watsons.com.cn//upload/5c3e51e4.jpg?w=720&h=960&x-oss-process=image/resize,w_1080",
          avatar:
            "https://img.xiaohongshu.com/avatar/5b7d198a7e6e15000155f7c9.jpg@80w_80h_90q_1e_1c_1x.jpg",
          title: "夏天用这款姨妈巾,让你体验真正的清爽",
          user: "迷人的小妖精迷人的小妖精",
          like: "953",
        },
        {
          img:
            "https://image.watsons.com.cn//upload/92761043.JPG?w=1000&h=999&x-oss-process=image/resize,w_1080",
          avatar:
            "https://img.xiaohongshu.com/avatar/5b7d198a7e6e15000155f7c9.jpg@80w_80h_90q_1e_1c_1x.jpg",
          title: "最近浴室新宠,日系神仙好物了解一下~",
          user: "迷人的小妖精迷人的小妖精123",
          like: "953",
        },
        {
          img:
            "https://image.watsons.com.cn//upload/da61c0f5.jpg?w=959&h=958&x-oss-process=image/resize,w_1080",
          avatar:
            "https://img.xiaohongshu.com/avatar/5b7d198a7e6e15000155f7c9.jpg@80w_80h_90q_1e_1c_1x.jpg",
          title: "千万不要去乱尝试贵妇级好用的水乳有哪些呢?千万不要去乱尝试",
          user: "迷人的小妖精迷人的小妖精",
          like: "953",
        },
        {
          img:
            "https://image.watsons.com.cn//upload/fcd68df4.jpg?w=1080&h=1080&x-oss-process=image/resize,w_1080",
          avatar:
            "https://img.xiaohongshu.com/avatar/5b7d198a7e6e15000155f7c9.jpg@80w_80h_90q_1e_1c_1x.jpg",
          title: "最近浴室新宠,日系神仙好物了解一下~",
          user: "迷人的小妖精迷人的小妖精",
          like: "953",
        },
        {
          img:
            "https://image.watsons.com.cn//upload/bef41e67.JPG?w=712&h=534&x-oss-process=image/resize,w_1080",
          avatar:
            "https://img.xiaohongshu.com/avatar/5b7d198a7e6e15000155f7c9.jpg@80w_80h_90q_1e_1c_1x.jpg",
          title: "夏天用这款姨妈巾,让你体验真正的清爽",
          user: "迷人的小妖精迷人的小妖精",
          like: "953",
        },
        {
          img:
            "https://image.watsons.com.cn//upload/25ab20fe.JPG?w=1000&h=1200&x-oss-process=image/resize,w_1080",
          avatar:
            "https://img.xiaohongshu.com/avatar/5b7d198a7e6e15000155f7c9.jpg@80w_80h_90q_1e_1c_1x.jpg",
          title: "150元搞定全套护肤品,这些护肤好物必须交出来!",
          user: "迷人的小妖精迷人的小妖精123",
          like: "953",
        },
        {
          img:
            "https://ci.xiaohongshu.com/eb971d00-05ab-5b2a-ba03-52d8f544c42b?imageView2/2/w/400/q/50/format/jpg",
          avatar:
            "https://img.xiaohongshu.com/avatar/5b7d198a7e6e15000155f7c9.jpg@80w_80h_90q_1e_1c_1x.jpg",
          title: "最近浴室新宠,日系神仙好物了解一下~",
          user: "迷人的小妖精迷人的小妖精",
          like: "953",
        },
        {
          img:
            "https://image.watsons.com.cn//upload/4a3c1788.jpg?w=823&h=1000&x-oss-process=image/resize,w_1080",
          avatar:
            "https://img.xiaohongshu.com/avatar/5b7d198a7e6e15000155f7c9.jpg@80w_80h_90q_1e_1c_1x.jpg",
          title: "夏天用这款姨妈巾,让你体验真正的清爽",
          user: "迷人的小妖精迷人的小妖精",
          like: "953",
        },
        {
          img:
            "https://image.watsons.com.cn//upload/0a89e6b7.jpg?w=1080&h=1920&x-oss-process=image/resize,w_1080",
          avatar:
            "https://img.xiaohongshu.com/avatar/5b7d198a7e6e15000155f7c9.jpg@80w_80h_90q_1e_1c_1x.jpg",
          title: "千万不要去乱尝试贵妇级好用的水乳有哪些呢?千万不要去乱尝试",
          user: "迷人的小妖精迷人的小妖精",
          like: "953",
        },
        {
          img:
            "https://image.watsons.com.cn//upload/99253111.jpg?w=1080&h=1920&x-oss-process=image/resize,w_1080",
          avatar:
            "https://img.xiaohongshu.com/avatar/5b7d198a7e6e15000155f7c9.jpg@80w_80h_90q_1e_1c_1x.jpg",
          title: "150元搞定全套护肤品,这些护肤好物必须交出来!",
          user: "迷人的小妖精迷人的小妖精123",
          like: "953",
        },
        {
          img:
            "https://image.watsons.com.cn//upload/13afe9a7.jpg?x-oss-process=image/resize,w_1080",
          avatar:
            "https://img.xiaohongshu.com/avatar/5b7d198a7e6e15000155f7c9.jpg@80w_80h_90q_1e_1c_1x.jpg",
          title:
            "贵妇级好用的水乳有哪些呢?千万不要去乱尝试贵妇级好用的水乳有哪些呢?千万不要去乱尝试贵妇级好用的水乳有哪些呢?千万不要去乱尝试",
          user: "迷人的小妖精迷人的小妖精",
          like: "953",
        },
        {
          img:
            "https://image.watsons.com.cn//upload/98c7c4c3.jpg?w=1210&h=1210&x-oss-process=image/resize,w_1080",
          avatar:
            "https://img.xiaohongshu.com/avatar/5b7d198a7e6e15000155f7c9.jpg@80w_80h_90q_1e_1c_1x.jpg",
          title: "150元搞定全套护肤品,这些护肤好物必须交出来!",
          user: "迷人的小妖精迷人的小妖精",
          like: "953",
        },
        {
          img:
            "https://image.watsons.com.cn//upload/54c5d7b4.jpg?w=828&h=991&x-oss-process=image/resize,w_1080",
          avatar:
            "https://img.xiaohongshu.com/avatar/5b7d198a7e6e15000155f7c9.jpg@80w_80h_90q_1e_1c_1x.jpg",
          title: "150元搞定全套护肤品,这些护肤好物必须交出来!",
          user: "迷人的小妖精迷人的小妖精",
          like: "953",
        },
        {
          img:
            "https://image.watsons.com.cn//upload/71d19462.jpg?x-oss-process=image/resize,w_1080",
          avatar:
            "https://img.xiaohongshu.com/avatar/5b7d198a7e6e15000155f7c9.jpg@80w_80h_90q_1e_1c_1x.jpg",
          title: "夏天用这款姨妈巾,让你体验真正的清爽",
          user: "迷人的小妖精迷人的小妖精123",
          like: "953",
        },
        {
          img:
            "https://image.watsons.com.cn//upload/642cb83c.jpeg?w=1080&h=1080&x-oss-process=image/resize,w_1080",
          avatar:
            "https://img.xiaohongshu.com/avatar/5b7d198a7e6e15000155f7c9.jpg@80w_80h_90q_1e_1c_1x.jpg",
          title: "150元搞定全套护肤品,这些护肤好物必须交出来!",
          user: "迷人的小妖精迷人的小妖精",
          like: "953",
        },
        {
          img:
            "https://image.watsons.com.cn//upload/31e42833.jpg?w=750&h=750&x-oss-process=image/resize,w_1080",
          avatar:
            "https://img.xiaohongshu.com/avatar/5b7d198a7e6e15000155f7c9.jpg@80w_80h_90q_1e_1c_1x.jpg",
          title: "150元搞定全套护肤品,这些护肤好物必须交出来!",
          user: "迷人的小妖精迷人的小妖精",
          like: "953",
        },
        {
          img:
            "https://image.watsons.com.cn//upload/92761043.JPG?w=1000&h=999&x-oss-process=image/resize,w_1080",
          avatar:
            "https://img.xiaohongshu.com/avatar/5b7d198a7e6e15000155f7c9.jpg@80w_80h_90q_1e_1c_1x.jpg",
          title: "夏天用这款姨妈巾,让你体验真正的清爽",
          user: "迷人的小妖精迷人的小妖精",
          like: "953",
        },
        {
          img:
            "https://image.watsons.com.cn//upload/60cc9b8e.jpg?w=991&h=744&x-oss-process=image/resize,w_1080",
          avatar:
            "https://img.xiaohongshu.com/avatar/5b7d198a7e6e15000155f7c9.jpg@80w_80h_90q_1e_1c_1x.jpg",
          title: "150元搞定全套护肤品,这些护肤好物必须交出来!",
          user: "迷人的小妖精迷人的小妖精123",
          like: "953",
        },
        {
          img:
            "https://image.watsons.com.cn//upload/b709ed72.jpg?w=552&h=414&x-oss-process=image/resize,w_1080",
          avatar:
            "https://img.xiaohongshu.com/avatar/5b7d198a7e6e15000155f7c9.jpg@80w_80h_90q_1e_1c_1x.jpg",
          title: "最近浴室新宠,日系神仙好物了解一下~",
          user: "迷人的小妖精迷人的小妖精",
          like: "953",
        },
        {
          img:
            "https://image.watsons.com.cn//upload/137b50b0.jpg?x-oss-process=image/resize,w_1080",
          avatar:
            "https://img.xiaohongshu.com/avatar/5b7d198a7e6e15000155f7c9.jpg@80w_80h_90q_1e_1c_1x.jpg",
          title: "夏天用这款姨妈巾,让你体验真正的清爽",
          user: "迷人的小妖精迷人的小妖精",
          like: "952",
        },
        {
          img:
            "https://image.watsons.com.cn//upload/31e42833.jpg?w=750&h=750&x-oss-process=image/resize,w_1080",
          avatar:
            "https://img.xiaohongshu.com/avatar/5b7d198a7e6e15000155f7c9.jpg@80w_80h_90q_1e_1c_1x.jpg",
          title: "最近浴室新宠,日系神仙好物了解一下~",
          user: "迷人的小妖精迷人的小妖精",
          like: "953",
        },
      ],
    };
  },

  methods: {
    loadmore() {
      console.log(9999);
      if (!this.loading) {
        this.loading = true;
        setTimeout(() => {
          this.data = this.data.concat(this.originData, this.originData);
          this.loading = false;
        }, 1000);
      }
    },
  },
  mounted() {
    console.log("cascadeShow");

    this.data = this.originData;
  },
};
</script>


<style  lang="less" scoped>
.container_water_fall {
  box-sizing: border-box;
  &.water_content {
    margin: 0 15px;
  }

  .cell_item {
    width: 100%;
    background: #ffffff;
    overflow: hidden;
    box-sizing: border-box;
    border-radius: 6px;
    margin-top: 10px;
    .cell_item_img {
      border-radius: 12px 12px 0 0;
      width: 100%;
      height: auto;
      display: block;
    }
    .item-body {
      //   border: 1px solid #F0F0F0;
      padding: 12px;
      .item-title {
        font-size: 30px;
        color: #333333;
        font-weight: bold;
      }
      .item-footer {
        position: relative;
        display: flex;
        justify-content: left;
        flex-direction: column;
        .avatar {
          width: 44px;
          height: 44px;
          border-radius: 50%;
          background-repeat: no-repeat;
          background-size: contain;
        }
        .name {
          font-size: 22px;
          color: #fc8800;
        }
        .like {
          right: 0;
          display: flex;
          align-items: center;

          .item_title {
            font-size: 30px;
            color: #f63b66;
          }
          .item_sold {
            font-size: 24px;
            text-overflow: ellipsis;
            overflow: hidden;
            white-space: nowrap;
            color: #999;
          }
        }
      }
    }
  }
}
</style>

index.less


.container-water-fall {

    box-sizing: border-box;
    &.water-content {
      margin: 0 15px;
    }
  
    h4 {
      padding-top: 56px;
      padding-bottom: 28px;
      font-family: PingFangSC-Medium;
      font-size: 36px;
      color: #000000;
      letter-spacing: 1px;
      text-align: justify;
    }
    button {
      background-color: #ff0;
      color: #24292e;
      border: 1px solid rgba(27, 31, 35, 0.2);
      border-radius: 0.25em;
      width: 100px;
      line-height: 26px;
      font-size: 13px;
      margin: 4px 0;
      margin-right: 4px;
      cursor: pointer;
      outline: none;
      &.blue-light {
        background: #27fbc2;
      }
    }
    button:hover {
      background-image: linear-gradient(-180deg, #fafbfc, #ccc 90%);
    }
  
    .cell-item {
      width: 100%;
      background: #ffffff;
      overflow: hidden;
      box-sizing: border-box;
      border-radius: 6px;
      margin-top: 10px;
      img {
        // border-radius: 12px 12px 0 0;
        width: 100%;
        height: auto;
        display: block;
      }
      .item-body {
        // border: 1px solid #F0F0F0;
        padding: 12px;
        .item-desc {
          font-size: 15px;
          color: #333333;
          line-height: 15px;
          font-weight: bold;
        }
        .item-footer {
          margin-top: 22px;
          position: relative;
          display: flex;
          align-items: center;
          .avatar {
            width: 44px;
            height: 44px;
            border-radius: 50%;
            background-repeat: no-repeat;
            background-size: contain;
          }
          .name {
            max-width: 150px;
            margin-left: 10px;
            font-size: 14px;
            color: #999999;
          }
          .like {
            position: absolute;
            right: 0;
            display: flex;
            align-items: center;
            &.active {
              i {
              }
              .like-total {
                color: #ff4479;
              }
            }
            i {
              width: 28px;
              display: block;
            }
            .like-total {
              margin-left: 10px;
              font-size: 12px;
              color: #999999;
            }
          }
        }
      }
    }
  }
  .githubdata {
    float: right;
    margin-right: 90px;
    img {
      width: 14px;
      // height: 16px;
    }
  }
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
vue-waterfall2 是一个 Vue.js 的瀑布流组件,可以实现类似 Pinterest 的布局效果。要实现触底加载功能,需要在组件中监听滚动事件,判断滚动条是否到达底部,然后触发加载更多数据的方法。 以下是一个简单的示例代码: ```vue <template> <waterfall :list="list" :options="options" @scroll="handleScroll"></waterfall> </template> <script> import Waterfall from 'vue-waterfall2' export default { components: { Waterfall }, data() { return { list: [], // 列表数据 options: { // 瀑布流配置项 }, currentPage: 1, // 当前页码 isEnd: false, // 是否已经加载完所有数据 } }, mounted() { this.loadMore() }, methods: { loadMore() { if (this.isEnd) return // 发送请求获取数据,这里假设返回一个 Promise 对象 fetchData(this.currentPage).then((data) => { if (data.length) { this.list = this.list.concat(data) this.currentPage++ } else { this.isEnd = true } }) }, handleScroll(position) { // 监听滚动事件 const { maxY } = position if (maxY <= window.innerHeight) { this.loadMore() } }, }, } </script> ``` 在这个示例中,我们定义了一个 `list` 数组来存放列表数据,`options` 对象用来配置瀑布流效果。在 `mounted` 钩子函数中,我们首次加载数据。`loadMore` 方法用来加载更多数据,其中 `fetchData` 方法用来发送网络请求获取数据。在 `handleScroll` 方法中,我们监听了 `waterfall` 组件的滚动事件,当滚动到底部时触发加载更多数据的方法。`isEnd` 变量用来判断是否已经加载完所有数据,避免重复请求。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

前端酱紫

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值