GithubHelp home page GithubHelp logo

lfyfly / vue-waterfall-easy Goto Github PK

View Code? Open in Web Editor NEW
845.0 13.0 352.0 2.58 MB

vue瀑布流组件(vue-waterfall-easy 2.x)

Home Page: https://lfyfly.github.io/vue-waterfall-easy/demo/#/

License: MIT License

JavaScript 46.47% HTML 0.97% Vue 51.58% CSS 0.98%
waterfall vue-waterfall-easy vue vue-waterfall

vue-waterfall-easy's Introduction

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

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

props type default description
width Number - 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 table
**If it is fixed width, you must set the width prop **, not just its parent element set fixed width
height Number|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 String
When 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
gap Number 20 [Pc] space between pictures(px)
mobileGap Number 8 [Mobile] space between pictures(px)
imgsArr Array [] required
Data used to render the waterfall stream
Each array element is an object and must have src and href attributes.
The src attribute represents the SRC attribute of the picture
The 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.
srcKey String 'src' When the key value of your picture address is not src, you can use this property to replace it.
hrefKey String 'href' When the key value of your picture address is not href, you can use this property to replace it.
imgWidth Number 240 The width of the picture(px)
maxCols Number 5 Waterfall shows the maximum number of columns
linkRange String 'card' Identify click to trigger jump link range
value:
'card' Whole card range
'img' image range
'custom' Customize the link range through slots
isRouterLink Boolean false Render the a tag when the value is false
Render the router-link component when the value is true
reachBottomDistance Number 0 The distance(px) from the bottom of the container when the scrolling triggers the scrollReachBottom event
loadingDotCount Number 3 The number of default loading animation dots
loadingDotStyle Object null The style object of the small dots in the default loading element
loadingTimeOut Number 500 Preloading events less than 500ms milliseconds do not display loading animations,increasing the user experience
cardAnimationClass String 'default-card-animation' the animation className for the card
enablePullDownEvent Boolean false enable the drop-down event

4. Event

event name description
scrollReachBottom When the scroll bar scrolls to the bottom,it is used to trigger a request for new image data
preloaded Trigger every time image preloading is completed
click Trigger when the card is clicked,look at an example under the table
imgError Trigger when img load error
pullDownMove The 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.
pullDownEnd The 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

parameterpar description
props.index The index of the image in the data array,starting from 0
props.value The 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">

vue-waterfall-easy's People

Contributors

lfyfly 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  avatar  avatar  avatar  avatar  avatar

vue-waterfall-easy's Issues

default slot中放置自定义的组件

现在的imgsArr中每个元素都要有src和href,我已经让每个元素有这两个属性了,不过除了这两个属性之外,还有很多其他属性,而基于每个元素里面的各种属性,我需要用自己的组件来呈现。
所以我希望把自定义组件放到默认的slot中,但是我看了例子并不知道如何把imgsArr中的当前元素传递到这个位置,而这个props里面好像也只有一个index属性。
<vue-waterfall-easy :imgsArr="imgsArr" @scrollReachBottom="getData"> <my-component class="img-info" slot-scope="props"> //???? </my-component> </vue-waterfall-easy>

请指教,多谢!

怎麼設置圖片的寬度?

大佬設置圖片寬度怎麼沒起效果?求教一下,謝謝。

data() {
return {
//圖片大小
imgsWidth: 80, }

图片比例没有传参控制么?

我们的功能是用户可以上传图片,为保证图片规范性,我们可能会需要限制图片最大或最小比例,这个功能应该向插件传什么参数呢?

PROP的imgsArr默认值要用函数返回。

Invalid default value for prop "imgsArr": Props with type Object/Array must use a factory function to return the default value.
官方文档写的:
// 对象或数组且一定会从一个工厂函数返回默认值

imgsArr和loadingDotStyle必须用函数返回。
loadingDotStyle: { type: Object, default: function () { return null; } },
imgsArr: { type: Array, required: true, default: function () { return []; } },

TypeError: Cannot read property 'forEach' of undefined

我在使用这个插件的时候遇到这个错误,已经好多天了,一直解决不了。
这是我的代码:
<script>
new Vue({
el: "#app",
components: {
vueWaterfallEasy
},
data() {
return {
imgsArr: [],
fechImgsArr: [],
group: 1,
}
},
methods: {
getData () {
axios.get("http://122.114.227.186:8080/" + this.group)
.then(res => {
this.imgsArr = res.data
this.group++
console.log(res.data)
})
},
},
created() {
this.getData()
}
})
</script>
这是我的后端返回的json:
image
这是chrome console下的结果:
image
可以看到res.data是有Array(0)属性的。
我查了很久的google,不管是用for in重组数组还是重写后端返回的json都解决不了这个问题,我很烦恼,各位大大能帮忙看一下吗?

h5页面,生成的页面底部栏太宽,显示出横向的滚动条出来了

如题,我遇到的问题是在开发h5页面时,用组件动态生成的页面中,会扩宽底部栏,把.vue-waterfall-easy所在的dom撑开,显示出横向的滚动条出来。我自己的解决办法是把宽度 width: 100%改成 width: 99.9%就好了。如下代码:

.vue-waterfall-easy {
  position: relative;
  width: 99.9%; // 移动端生效
}

img error

请问下图片加载失败的情况,图片的高度怎么算的

我这个渣渣,按教程在vue里面一步一步写,全写完了,没报错,但是啥东西也没出来,console.log(res.data)也有数据出来

我这个渣渣,按教程在vue里面一步一步写,全写完了,没报错,但是啥东西也没出来,console.log(res.data)也有数据出来
(20) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}]
0
:
href
:
(...)
info
:
"一些图片描述文字"
src
:
(...)
_height
:
251
ob
:
Observer {value: {…}, dep: Dep, vmCount: 0}
get href
:
ƒ reactiveGetter()

请问模板语法能换成vue默认的嘛?

Module build failed: ReferenceError: Unknown plugin "transform-vue-jsx" specified in "E:\Testing\mp-kite\node_modules\vue-waterfall-easy\.babelrc" at 0, attempted to resolve relative to "E:\Testing\mp-kite\node_modules\vue-waterfall-easy"
at E:\Testing\mp-kite\node_modules\babel-core\lib\transformation\file\options\option-manager.js:180:17
at Array.map (native)
at Function.normalisePlugins (E:\Testing\mp-kite\node_modules\babel-core\lib\transformation\file\options\option-manager.js:158:20)
at OptionManager.mergeOptions (E:\Testing\mp-kite\node_modules\babel-core\lib\transformation\file\options\option-manager.js:234:36)
at OptionManager.init (E:\Testing\mp-kite\node_modules\babel-core\lib\transformation\file\options\option-manager.js:368:12)
at File.initOptions (E:\Testing\mp-kite\node_modules\babel-core\lib\transformation\file\index.js:212:65)
at new File (E:\Testing\mp-kite\node_modules\babel-core\lib\transformation\file\index.js:135:24)
at Pipeline.transform (E:\Testing\mp-kite\node_modules\babel-core\lib\transformation\pipeline.js:46:16)
at transpile (E:\Testing\mp-kite\node_modules\babel-loader\lib\index.js:50:20)
at Object.module.exports (E:\Testing\mp-kite\node_modules\babel-loader\lib\index.js:173:20)

@ .//vue-waterfall-easy/src/vue-waterfall-easy/vue-waterfall-easy.vue 8:0-123
@ ./
/babel-loader/lib!./~/mpvue-loader/lib/selector.js?type=script&index=0!./src/pages/find-list/find-list.vue
@ ./src/pages/find-list/find-list.vue
@ ./src/pages/find-list/main.js

由于该组件使用了jsx语法,导致运行出错

建议 height 属性更灵活点

看了源码,height 只能传递数字(实际单位是像素),有点不方便。
可能有的需求是想设置 90vh,或者 100rem ,或者 calc(100vh - 200px)

TypeError: Cannot read property 'src' of undefined

用的npm 的方式安装的vue-waterfall-easy,然后按照Basic example方式实现,运行时候控制台报错:
TypeError: Cannot read property 'src' of undefined
at eval (vueWaterfallEasy.js?6dc5:1)
at Array.forEach ()
at VueComponent.preload (vueWaterfallEasy.js?6dc5:1)
at VueComponent.imgsArr (vueWaterfallEasy.js?6dc5:1)
at Watcher.run (vue.esm.js?a026:3233)
at flushSchedulerQueue (vue.esm.js?a026:2981)
at Array.eval (vue.esm.js?a026:1837)
at flushCallbacks (vue.esm.js?a026:1758)

因为是初学者,不知道是不是缺少什么package的问题,还请麻烦解惑,谢谢

Update list

waterfall-over 的top 值不对,

waterfall-over

waterfall-over 的top值,在倒数第二个的位置,

正常应该在倒数第一个的top位置吧?

"vue-waterfall-easy": "^2.2.2",

不能显示图片

我在那种切换的列表,上面是一个切换列表,下面根据切换内容,切换子组件,但是子组件被盖住,不显示图片[图片]

import plugin error

hi
thansk for your plugin but when i use this, it's occur an error in
#error (compile error)
in .//babel-loader/lib!.//vue-loader/lib/selector.js?type=script&index=0!./~/vue-waterfall-easy/src/vue-waterfall-easy/vue-waterfall-easy.vue
Module build failed: ReferenceError: Unknown plugin "transform-vue-jsx" specified in "my file path"
node_modules/vue-waterfall-easy/.babelrc" at 0, attempted to resolve relative to "/node_modules/vue-waterfall-easy"
at /node_modules/babel-core/lib/transformation/file/options/option-manager.js:180:17
at Array.map (native)
at Function.normalisePlugins (//node_modules/babel-core/lib/transformation/file/options/option-manager.js:158:20)
at OptionManager.mergeOptions (/node_modules/babel-core/lib/transformation/file/options/option-manager.js:234:36)
at OptionManager.init /node_modules/babel-core/lib/transformation/file/options/option-manager.js:368:12)
at File.initOptions (//node_modules/babel-core/lib/transformation/file/index.js:212:65)
at new File (/node_modules/babel-core/lib/transformation/file/index.js:135:24)
at Pipeline.transform (node_modules/babel-core/lib/transformation/pipeline.js:46:16)
at transpile (/node_modules/babel-loader/lib/index.js:49:20)

waiting your apply thanks

相对路径图片引用不成功

1.vue-cli创建的项目,我把图片放到src里面 展示不了图片,放到static里面就可以,是怎么回事呢
2. 还有info怎么去掉 我在页面内重写了css,覆盖不了

加载新的数据后,列表数据会重新reload

bug:
触发scrollReachBottom方法时候,调用this.imgsArr = this.imgsArr.concat(tempData);
会导致数据重新加载,滚动条默认回到顶部。

新版2.4.2存在此问题,旧版本2.1.9正常

图片可否支持懒加载

因为有些图片尺寸较大,先拿图片再加载有点慢,可否支持懒加载,或者说可以把img标签以slot暴露出来,我们自己做懒加载

有个小bug

滚动触底事件中有个小bug,部分极端高度下会发生,需要将判断条件修改下
image

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.