|
| 1 | + |
| 2 | + |
| 3 | + |
| 4 | +#### [中文版文档](https://github.com/AwesomeDevin/vue-waterfall2/blob/master/CHINESE-README.md) |
| 5 | +# vue-waterfall2 |
| 6 | + 1. auto adaption for width and height |
| 7 | + 2. High degree of customization |
| 8 | + 3. support lazy load(attribute with `lazy-src`) |
| 9 | + |
| 10 | + |
| 11 | + |
| 12 | + |
| 13 | +If you have some questions,welcome to describe issues、suggestions;Thank you for your Star ! |
| 14 | +[Welcome to my blog !!!](https://github.com/AwesomeDevin/blog) |
| 15 | + |
| 16 | + |
| 17 | +## Demo |
| 18 | +[Common Demo](http://47.105.188.15:3001/) |
| 19 | +[Lazyload Demo](http://47.105.188.15:3001/#/list) |
| 20 | +[Code Demo](https://codesandbox.io/embed/vue-template-99ps6) |
| 21 | + |
| 22 | + |
| 23 | + |
| 24 | + |
| 25 | + |
| 26 | +[GITHUB](https://github.com/Rise-Devin/vue-waterfall2) |
| 27 | +``` |
| 28 | +npm i |
| 29 | +npm run dev |
| 30 | +``` |
| 31 | + |
| 32 | +## Installation |
| 33 | +``` |
| 34 | + npm i vue-waterfall2@latest --save |
| 35 | +``` |
| 36 | + |
| 37 | +## <waterfall> Props |
| 38 | +Name | Default | Type | Desc |
| 39 | +-------- | -------- | -------- | -------- |
| 40 | +height | null | Number | height of container |
| 41 | +col | 2 | Number | The number of column |
| 42 | +width | null | Number | The width of each column |
| 43 | +gutterWidth | 10 | Number | The value of margin |
| 44 | +data | [] | Array | data |
| 45 | +isTransition | true | Boolean | load image with transition |
| 46 | +lazyDistance | 300 | Number | The distance of image lazy loading |
| 47 | +loadDistance | 300 | Number | The distance of loadmore |
| 48 | + |
| 49 | +## Lazy Load |
| 50 | +For images that need to be loaded lazily, the 'lazy-src' attribute needs to be used |
| 51 | +```html |
| 52 | +<waterfall :col='col' :data="data" > |
| 53 | + <template> |
| 54 | + <img v-if="item.img" :lazy-src="item.img" alt="load error" /> |
| 55 | + </template> |
| 56 | +</waterfall> |
| 57 | +``` |
| 58 | + |
| 59 | +## <waterfall> Events |
| 60 | +Name | Data | Desc |
| 61 | +-------- | --- | -------- |
| 62 | +loadmore | - | Scroll to the bottom to trigger on PC / pull up to trigger on Mobile |
| 63 | +scroll | obj | Scroll to trigger and get the infomation of scroll |
| 64 | +finish | - | finish render |
| 65 | + |
| 66 | +## $waterfall API |
| 67 | +``` |
| 68 | +this.$waterfall.forceUpdate() //forceUpdate |
| 69 | +``` |
| 70 | + |
| 71 | +## Usage |
| 72 | +Notes: |
| 73 | + 1. attribute `gutterWidth` needs to be used together with `width` to be effective, otherwise it will be adaptive width (when using `rem` to layout, calculate the width after adaptation before passing the value). |
| 74 | + 2. Use the parent component of 'waterfall' if there is a problem with the style, remove CSS `scoped` and try it |
| 75 | +##### main.js |
| 76 | +```javascript |
| 77 | +import waterfall from 'vue-waterfall2' |
| 78 | +Vue.use(waterfall) |
| 79 | +``` |
| 80 | +##### app.vue |
| 81 | +```javascript |
| 82 | +<template> |
| 83 | + <div class="container-water-fall"> |
| 84 | + <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> |
| 85 | + |
| 86 | + <waterfall :col='col' :width="itemWidth" :gutterWidth="gutterWidth" :data="data" @loadmore="loadmore" @scroll="scroll" > |
| 87 | + <template > |
| 88 | + <div class="cell-item" v-for="(item,index) in data"> |
| 89 | + <div class="item-body"> |
| 90 | + <div class="item-desc">{{item.title}}</div> |
| 91 | + <div class="item-footer"> |
| 92 | + <div class="avatar" :style="{backgroundImage : `url(${item.avatar})` }"></div> |
| 93 | + <div class="name">{{item.user}}</div> |
| 94 | + <div class="like" :class="item.liked?'active':''" > |
| 95 | + <i ></i> |
| 96 | + <div class="like-total">{{item.liked}}</div> |
| 97 | + </div> |
| 98 | + </div> |
| 99 | + </div> |
| 100 | + </div> |
| 101 | + </template> |
| 102 | + </waterfall> |
| 103 | + |
| 104 | + </div> |
| 105 | +</template> |
| 106 | + |
| 107 | + |
| 108 | +/* |
| 109 | + notes: |
| 110 | + 1. attribute `gutterWidth` needs to be used together with `width` to be effective, otherwise it will be adaptive width (when using `rem` to layout, calculate the width after adaptation before passing the value). |
| 111 | + 2. Use the parent component of 'waterfall' if there is a problem with the style, remove CSS 'scoped' and try it |
| 112 | +*/ |
| 113 | + |
| 114 | +import Vue from 'vue' |
| 115 | + export default{ |
| 116 | + data(){ |
| 117 | + return{ |
| 118 | + data:[], |
| 119 | + col:5, |
| 120 | + } |
| 121 | + }, |
| 122 | + computed:{ |
| 123 | + itemWidth(){ |
| 124 | + return (138*0.5*(document.documentElement.clientWidth/375)) #rem to layout, Calculate the value of width |
| 125 | + }, |
| 126 | + gutterWidth(){ |
| 127 | + return (9*0.5*(document.documentElement.clientWidth/375)) #rem to layout, Calculate the value of margin |
| 128 | + } |
| 129 | + }, |
| 130 | + methods:{ |
| 131 | + scroll(scrollData){ |
| 132 | + console.log(scrollData) |
| 133 | + }, |
| 134 | + switchCol(col){ |
| 135 | + this.col = col |
| 136 | + console.log(this.col) |
| 137 | + }, |
| 138 | + loadmore(index){ |
| 139 | + this.data = this.data.concat(this.data) |
| 140 | + } |
| 141 | + } |
| 142 | + } |
| 143 | +``` |
0 commit comments