Giter Club home page Giter Club logo

vue-waterfall2's Introduction

Note: [email protected] is adapt for vue3, if your app is vue2, please use [email protected], 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
Vue2 Code Demo
Vue3 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)
	      }
	    }
	}

Stargazers

Stargazers repo roster for @AwesomeDevin/vue-waterfall2

Forkers

Forkers repo roster for @AwesomeDevin/vue-waterfall2

vue-waterfall2's People

Contributors

awesomedevin avatar dependabot[bot] avatar shengwendi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vue-waterfall2's Issues

有办法让图片一张张显示吗?

我项目的图片是一张张请求的, 我发现图片都是全部现在<div class="slot-box"></div>里,然后在一次性渲染出来的。大佬有办法让他一张张来吗?

加急问题

@AwesomeDevin
Uncaught TypeError: Cannot read property 'appendChild' of undefined
at VueComponent.init (waterfall.vue?88a6:106)
at eval (waterfall.vue?88a6:228)
样式正常显示,刷新页面会报错,偶尔不报错!尊敬的作者,请您尽快解决这个问题?上线项目,实在是着急!能提供一下您的联系方式吗?(我的联系方式 QQ 741350922)

引用了这个包,Uglify构建报错

引用了这个包后,Uglify构建的时候报错:

ERROR in app.js from UglifyJs
Unexpected token: punc «(» [app.js:555,6]

引用es5文件夹里面的话,var _waterfall = require('./waterfall.vue');
这个路径没写对

跪求大佬修复!!!

报错了Uncaught RangeError: Maximum call stack size exceeded

Uncaught RangeError: Maximum call stack size exceeded
at initState (vue.runtime.esm.js?0261:4640)
at VueComponent.Vue._init (vue.runtime.esm.js?0261:5006)
at new VueComponent (vue.runtime.esm.js?0261:5154)
at createComponentInstanceForVnode (vue.runtime.esm.js?0261:3283)
at init (vue.runtime.esm.js?0261:3114)
at createComponent (vue.runtime.esm.js?0261:5978)
at createElm (vue.runtime.esm.js?0261:5925)
at createChildren (vue.runtime.esm.js?0261:6053)
at createElm (vue.runtime.esm.js?0261:5954)
at VueComponent.patch [as patch] (vue.runtime.esm.js?0261:6477)

为什么

Property or method "height" is not defined

Property or method "height" is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option, or for class-based components, by initializing the property.
一进来就报错

所有图片都加载在第一列

                                <waterfall :col='col' :width="itemWidth" :gutterWidth="gutterWidth"  :data="picBox">
                                <template >
                                    <div class="cell-item" v-for="(item,index) in picBox" :key="index">
                                    <img  :src="item.ImgUrl" /> 
                                    <div class="item-body">
                                        <div class="item-desc">{{item.CellTypeHistory}}</div>
                                    </div>
                                </div>
                                </template>
                                </waterfall>   

页面滚动到底部,loadmore 事件不触发

请检查全局 CSS,看是否设置了 html { height: 100%; }

当高度为 100% 的时候,是不会触发 loadmore 事件的。

如果你引入的 CSS 是全局的,那么请在当前组件内添加CSS。style 不要添加 scoped 属性。

解决方案

<style>
html{
  height: auto !important;
}
</style>

找了好久的问题,终于找到了,希望能对大家有所帮助。

搜索框点击搜索报错

版本"vue-waterfall2": "^1.9.6"
问题描述:搜索框输入内容,点击搜索后调用接口,返回数据给data赋值报错;接口返回正确,打印赋值成功;
报错信息:[Vue warn]: Error in nextTick: "NotFoundError: Failed to execute 'insertBefore' on 'Node': The node before which the new node is to be inserted is not a child of this node.";
加了nextTick无效

请问下组件中怎么使用

Unknown custom element: - did you register the component correctly? For recursive components, make sure to provide the "name" option.

过渡效果似乎会报错

红字报错如下
`vue.runtime.esm.js?2b0e:619 [Vue warn]: Property or method "isTransition" is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option, or for class-based components, by initializing the property. See: https://vuejs.org/v2/guide/reactivity.html#Declaring-Reactive-Properties.

found in

---> at node_modules/vue-waterfall2/waterfall.vue
at node_modules/cube-ui/src/components/scroll/scroll.vue
at src/views/Mall.vue
at src/views/Index.vue
at src/App.vue
`

不知道是为什么

当切换绑定的数据源时,组件不能重新渲染

<waterfall
      :col="col"
      :data="data"
      @loadmore="loadmore"
>
.....
</waterfall>

动态绑定的 data,当切换数据源时,组件并不能重新渲染。我没有找到相关的 API 能帮我重置组件。

所以,我用 v-if 来动态渲染,这是比较简单的一种解决方式。

监听数据源,当数据发生变化时,我就用 v-if 来做重新渲染组件这件事情。

v-if="isShow"
// watch
this.isShow = false
setTimeout(() => {
    this.isShow = true
}, 100)

我想知道除了这种方式还有没有其他的方式?

关于loadmore触发机制问题

版本:"vue-waterfall2": "^1.9.6"
问题描述:loadmore的触发机制让我有点费解,我在第一次进入页面的时候loadDistance写的很小,滚动部分在我页面下部分,应该达到触发条件,但是没有执行,我稍微把页面向下拖动一点就触发了,我想让页面已进入就触发loadmore怎么做呢?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.