vue-waterfall2

1.10.9 • Public • Published

Note: vue-waterfall2@2.x is adapt for vue3, if your app is vue2, please use vue-waterfall2@1.10.x, 1.10.x document

vue-waterfall2

  1. auto adaption for width and height
  2. High degree of customization
  3. Swipe to the bottom to trigger on pc/android, pull up to trigger on ios
  4. Support lazy load(attribute with lazy-src)
  5. Easy to use, for PC/ios/android

The demo on mobile device

If you have some questions,welcome to describe issues、suggestions;Thank you for your Star !
Welcome to my blog !!!

Demo

Common Demo
Lazyload Demo
Code Demo

GITHUB

npm i 
npm run dev

Installation

 npm i vue-waterfall2@latest --save

Props

Name Default Type Desc
height null Number height of container
col 2 Number The number of column
width null Number The width of each column
gutterWidth 10 Number The value of margin
data [] Array data
isTransition true Boolean load image with transition
lazyDistance 300 Number The distance of image lazy loading
loadDistance 300 Number The distance of loadmore

Lazy Load

For images that need to be loaded lazily, the 'lazy-src' attribute needs to be used

<waterfall :col='col'   :data="data"     >
  <img v-if="item.img" :lazy-src="item.img" alt="load error"  />
</waterfall>

Events

Name Data Desc
loadmore - Scroll to the bottom to trigger on PC / pull up to trigger on Mobile
scroll obj Scroll to trigger and get the infomation of scroll
finish - finish render

$waterfall API

this.$waterfall.forceUpdate()   //forceUpdate

Usage

Notes:

  1. when using rem to layout, calculate the width after adaptation before passing the value.
  2. Use the parent component of 'waterfall' if there is a problem with the style, remove CSS scoped and try it
main.js
import { createApp } from "vue";
import waterfall from 'vue-waterfall2'

const app = createApp(App)
app.use(waterfall)
app.vue
<template>
  <div class="container-water-fall">
    <div><button  @click="loadmore">loadmore</button> <button @click="mix">mix</button> <button @click="switchCol('5')">5列</button> <button @click="switchCol('8')">8列</button> <button @click="switchCol('10')">10列</button> </div>

    <waterfall :col='col' :width="itemWidth" :gutterWidth="gutterWidth"  :data="data"  @loadmore="loadmore"  @scroll="scroll"  >
      <div class="cell-item" v-for="(item,index) in data">
        <div class="item-body">
            <div class="item-desc">{{item.title}}</div>
            <div class="item-footer">
                <div class="avatar" :style="{backgroundImage : `url(${item.avatar})` }"></div>
                <div class="name">{{item.user}}</div>
                <div class="like" :class="item.liked?'active':''" >
                    <i ></i>
                    <div class="like-total">{{item.liked}}</div>  
                </div>
            </div>
        </div>
      </div>
    </waterfall>
    
  </div>
</template>


/*
  notes:
  1. when using `rem` to layout, calculate the width after adaptation before passing the value.
  2. Use the parent component of 'waterfall' if there is a problem with the style, remove CSS 'scoped' and try it
*/

import Vue from 'vue'
	export default{
	    data(){
	        return{
	            data:[],
	            col:5,
	        }
	    },
	    computed:{
	      itemWidth(){  
	            return (138*0.5*(document.documentElement.clientWidth/375))  #rem to layout, Calculate the value of width 
	      },
	      gutterWidth(){
	            return (9*0.5*(document.documentElement.clientWidth/375)) #rem to layout, Calculate the value of margin 
	      }
	    },
	    methods:{
            scroll(scrollData){
                console.log(scrollData)
            },
	        switchCol(col){
	            this.col = col
	            console.log(this.col)
	      },
	      loadmore(index){
	            this.data = this.data.concat(this.data)
	      }
	    }
	}

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
1.10.9131latest

Version History

VersionDownloads (Last 7 Days)Published
1.10.9131
2.0.751
2.0.60
2.0.51
2.0.41
2.0.30
1.10.713
2.0.20
1.10.7-beta.10
2.0.15
2.0.00
2.0.0-beta.10
1.10.69
1.10.50
1.10.40
1.10.30
1.10.21
1.10.150
1.9.62
1.9.50
1.9.40
1.9.30
1.9.214
1.9.10
1.8.220
1.8.210
1.8.201
1.8.190
1.8.180
1.8.170
1.8.160
1.8.140
1.8.130
1.8.120
1.8.110
1.8.100
1.8.90
1.8.80
1.8.71
1.8.60
1.8.50
1.8.40
1.8.30
1.8.20
1.8.10
1.7.70
1.7.60
1.7.51
1.7.40
1.7.30
1.7.20
1.7.10
1.6.50
1.6.40
1.6.20
1.6.10
1.6.00
1.5.20
1.5.10
1.5.00
1.4.40
1.4.30
1.4.20
1.4.10
1.4.00
1.3.00
1.2.70
1.2.60
1.2.50
1.2.40
1.2.30
1.2.21
1.2.10
1.1.20
1.1.10
1.1.00
1.0.100
1.0.90
1.0.80
1.0.70
1.0.60
1.0.50
1.0.40
1.0.31
1.0.20
1.0.10
1.0.00

Package Sidebar

Install

npm i vue-waterfall2

Weekly Downloads

283

Version

1.10.9

License

MIT

Unpacked Size

20.4 kB

Total Files

8

Last publish

Collaborators

  • rise-devin