2.4.4 • Published 5 years ago

vue-waterfall-easy v2.4.4

Weekly downloads
427
License
MIT
Repository
github
Last release
5 years ago

vue-waterfall-easy 2.x

  1. This is a vue component that contains waterfall flow layout and infinite scroll loading
  2. Compared to other implementations,there is no need to specify the width and height of the image in the returned data
  3. It is because of the second item that the image is preloaded and then layout
  4. Responsive layout,adapt mobile
  5. Simple to use

中文文档

Demo

code of demo

update list

github

1. Usage

1.1 Installation

npm install vue-waterfall-easy --save

1.2 es6 import

import vueWaterfallEasy from 'vue-waterfall-easy'
export default {
  name: 'app',
  components: {
    vueWaterfallEasy
  }
}

1.3 scripts import

download vueWaterfallEasy.js

<script src="path/to/vue/vue.js"></script>
<script src="path/to/vueWaterfallEasy.js"></script>
new Vue({
  el: '#app',
  components: {
    vueWaterfallEasy
  }
})

1.4 Supports require.js and sea.js module import

2. Basic example

html

<vue-waterfall-easy :imgsArr="imgsArr" @scrollReachBottom="getData"></vue-waterfall-easy>

If imgArr is a replacement update, the data returned by the getData method new request overwrites the original data.

If imgArr is an incremental update, the data returned by the new request of getData method is merged with the original data. At this time, it is not recommended to use the replacement update, which will waste performance. The following example is an incremental update.

js

import vueWaterfallEasy from './vue-waterfall-easy/vue-waterfall-easy.vue'
import axios from 'axios'
export default {
  name: 'app',
  data() {
    return {
      imgsArr: [],
      group: 0,// request param
    }
  },
  components: {
    vueWaterfallEasy
  },
  methods: {
    getData() {
      // In the real environment,the backend will return a new image array based on the parameter group.
      // Here I simulate it with a stunned json file.
      axios.get('./static/mock/data.json?group=' + this.group)
        .then(res => {
          this.imgsArr = this.imgsArr.concat(res.data)
          this.group++
        })
    },
  },
  created() {
    this.getData()
  }
}

more detail see App.vue file

3. Props

propstypedefaultdescription
widthNumber-Container width(px),default is 100% relative parent element width,Due to the responsiveness,all its parent's width must be 100% relative to the browser window at this time,See the example after the tableIf it is fixed width, you must set the width prop , not just its parent element set fixed width
heightNumber|String-Container height, the default unit px for the value of the Number type, the unit can be specified when the value is the type of StringWhen you do not specify the height value, the default is relative to the height of the parent element 100%, then the parent element must have a height
gapNumber20Pc space between pictures(px)
mobileGapNumber8Mobile space between pictures(px)
imgsArrArray[]requiredData used to render the waterfall streamEach array element is an object and must have src and href attributes.The src attribute represents the SRC attribute of the pictureThe href attribute represents the link to click to jump if your key is not src and href, you can use the two properties of srcKey and hrefKey to do the key value replacement.
srcKeyString'src'When the key value of your picture address is not src, you can use this property to replace it.
hrefKeyString'href'When the key value of your picture address is not href, you can use this property to replace it.
imgWidthNumber240The width of the picture(px)
maxColsNumber5Waterfall shows the maximum number of columns
linkRangeString'card'Identify click to trigger jump link rangevalue:'card' Whole card range 'img' image range 'custom' Customize the link range through slots
isRouterLinkBooleanfalseRender the a tag when the value is falseRender the router-link component when the value is true
reachBottomDistanceNumber0The distance(px) from the bottom of the container when the scrolling triggers the scrollReachBottom event
loadingDotCountNumber3The number of default loading animation dots
loadingDotStyleObjectnullThe style object of the small dots in the default loading element
loadingTimeOutNumber500Preloading events less than 500ms milliseconds do not display loading animations,increasing the user experience
cardAnimationClassString'default-card-animation'the animation className for the card
enablePullDownEventBooleanfalseenable the drop-down event

4. Event

event namedescription
scrollReachBottomWhen the scroll bar scrolls to the bottom,it is used to trigger a request for new image data
preloadedTrigger every time image preloading is completed
clickTrigger when the card is clicked,look at an example under the table
imgErrorTrigger when img load error
pullDownMoveThe mobile terminal takes effect, touches the pull-down event, and the first parameter can obtain the Y-axis moving distance difference, which is often used for pull-down refresh.
pullDownEndThe mobile terminal takes effect, and the touch pull-down event is raised by the finger, which is often used for pull-down refresh.

click event demo

<vue-waterfall-easy :imgsArr="imgsArr" @scrollReachBottom="getData" @click="clickFn"></vue-waterfall-easy>
  clickFn(event, { index, value }) {
    // Prevent a tag jump
    event.preventDefault()
    // Do it only when you click on the image
    if (event.target.tagName.toLowerCase() == 'img') {
      console.log('img clicked',index, value)
    }
  }

5. methods

5.1 waterfallOver

When the rolling load data is over, manual invoking will remove the scroll event.

this.$refs.waterfall.waterfallOver()

more detail see App.vue

6. slot

6.1 default slot

Custom picture description element

parameter

parameterpardescription
props.indexThe index of the image in the data array,starting from 0
props.valueThe value of imgsArr item
<vue-waterfall-easy :imgsArr="imgsArr" @scrollReachBottom="getData">
  <div class="img-info" slot-scope="props">
    <p class="some-info">picture index: {{props.index}}</p>
    <p class="some-info">{{props.value.info}}</p>
  </div>
</vue-waterfall-easy>

6.2 slot="loading"

Custom loading element

<div slot="loading" slot-scope="{isFirstLoad}">
  <div slot="loading" v-if="isFirstLoad">first-loading...</div>
  <div v-else="v-else">loading...</div>
</div>

6.3 slot="waterfall-head"

Waterfall container head slot

<vue-waterfall-easy :imgsArr="imgsArr" @scrollReachBottom="getData">
  <div slot="waterfall-head">waterfall-head</div>
</vue-waterfall-easy>

6.4 slot="waterfall-over"

when waterfallOver method is called,this slot will show

<vue-waterfall-easy :imgsArr="imgsArr" @scrollReachBottom="getData">
  <div slot="waterfall-over">waterfall-over</div>
</vue-waterfall-easy>

7. Adapted mobile

Don't forget to add following code in index.html \<head>

<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no">
2.4.4

5 years ago

2.4.3

6 years ago

2.4.2

6 years ago

2.4.1

6 years ago

2.4.0

6 years ago

2.3.1

6 years ago

2.3.0

6 years ago

2.2.4

6 years ago

2.2.3

6 years ago

2.2.2

6 years ago

2.2.1

6 years ago

2.2.0

6 years ago

2.1.9

6 years ago

2.1.8

6 years ago

2.1.7

6 years ago

2.1.6

6 years ago

2.1.5

6 years ago

2.1.4

6 years ago

2.1.2

6 years ago

2.1.1

6 years ago

2.1.0

6 years ago

2.0.8

6 years ago

2.0.7

6 years ago

2.0.6

6 years ago

2.0.5

6 years ago

2.0.4

6 years ago

2.0.3

6 years ago

2.0.2

6 years ago

2.0.1

6 years ago

2.0.0

6 years ago

1.0.8

7 years ago

1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago