Vue Scroller:Vue 下拉刷新及无限加载组件
Vue Scroller
Vue Scroller is a foundational component ofVonic UI. In purpose of smooth scrolling, pull to refresh and infinite loading.
Demo
Change Logs
- v0.3.9 add getPosition method for scroller instance.
- v0.3.8 fix bug
- v0.3.7 publish bower version
- v0.3.6 support mouse events
- v0.3.4 change required property 'delegate-id' to non-required.
- v0.3.3 support multi scrollers in one page.
How To Use
Step 1: create vue project and install vue-scroller via npm. (we use vue webpack-simple template here)
$ vue init webpack-simple#1.0 my-project
$ cd my-project
$ npm install
$ npm install vue-scroller
Step 2: add resolve option and loader in webpack.config.js as below.
module.exports = {
// ...
resolve: {
extensions: ['', '.js', '.vue'],
fallback: [path.join(__dirname, './node_modules')]
},
// ...
module: {
loaders: [
// ...
{
test: /vue-scroller.src.*?js$/,
loader: 'babel'
}
]
},
// ...
}
Step 3: copy codes below to overwrite App.vue
<template>
<scroller delegate-id="myScroller"
:on-refresh="refresh"
:on-infinite="loadMore"
v-ref:my_scroller>
<div v-for="(index, item) in items" @click="onItemClick(index, item)"
class="row" :class="{'grey-bg': index % 2 == 0}">
{{ item }}
</div>
</scroller>
</template> <script>
import Scroller from 'vue-scroller' export default {
components: {
Scroller
}, data () {
return {
items: []
}
}, ready() { for (let i = 1; i <= 20; i++) {
this.items.push(i + ' - keep walking, be 2 with you.')
}
this.top = 1
this.bottom = 20 setTimeout(() => {
/* 下面2种方式都可以调用 resize 方法 */
// 1. use scroller accessor
$scroller.get('myScroller').resize() // 2. use component ref
// this.$refs.my_scroller.resize()
})
}, methods: {
refresh() {
setTimeout(() => {
let start = this.top - 1 for (let i = start; i > start - 10; i--) {
this.items.splice(0, 0, i + ' - keep walking, be 2 with you.')
} this.top = this.top - 10; /* 下面3种方式都可以调用 finishPullToRefresh 方法 */ // this.$broadcast('$finishPullToRefresh')
$scroller.get('myScroller').finishPullToRefresh()
// this.$refs.my_scroller.finishPullToRefresh() }, 1500)
}, loadMore() {
setTimeout(() => { let start = this.bottom + 1 for (let i = start; i < start + 10; i++) {
this.items.push(i + ' - keep walking, be 2 with you.')
} this.bottom = this.bottom + 10; setTimeout(() => {
$scroller.get('myScroller').resize()
})
}, 1500)
}, onItemClick(index, item) {
console.log(index)
}
} }
</script> <style>
html, body {
margin: 0;
} * {
box-sizing: border-box;
} .row {
width: 100%;
height: 50px;
padding: 10px 0;
font-size: 16px;
line-height: 30px;
text-align: center;
color: #444;
background-color: #fff;
} .grey-bg {
background-color: #eee;
}
</style>
Step 4: add viewport meta in index.html
<meta name="viewport" content="width=device-width, user-scalable=no">
Step 5: run the project
$ npm run dev
Scroller instance API
Methods
- resize :Void
- triggerPullToRefresh :Void
- Void finishPullToRefresh :Void
- scrollTo(x:Integer, y:Integer, animate:Boolean) :Void
- scrollBy(x:Integer, y:Integer, animate:Boolean) :Void
- getPosition :Object
That's it, have fun.
Vue Scroller:Vue 下拉刷新及无限加载组件的更多相关文章
- Vue 下拉刷新及无限加载组件
原文 https://github.com/wangdahoo/vue-scroller 主题 Vue.js Vue Scroller Vue Scroller is a foundational ...
- jQuery WeUI 组件下拉刷新和滚动加载的实现
最近在做手机版使用到了下拉刷新和滚动加载,记录一下实现过程: 一.引入文件 ? 1 2 3 4 <link rel="stylesheet" href="Conte ...
- 实现select下拉框的无限加载(懒加载)
在实际开发中我们有时无法避免select下拉功能数据过大导致页面卡顿(如在我在一次迭代中有一个select项接口返回了5000多条数据).用户体验差!结合实际开发给出了3个解决方案: 方案1.sele ...
- 第三方 XListview 上拉加载、下拉刷新、分页加载和Gson解析
注意:此Demo用的是第三方的Xlistview.jar,需要复制me文件夹到项目中,两个XML布局文件和一张图片 把下面的复制到String中 <string name="xlist ...
- mui 动态加载数据出现的问题处理 (silder轮播组件 indexedList索引列表 下拉刷新不能继续加载数据)
mui-slider 问题:动态给mui的图片轮播添加图片,轮播不滚动. 解决:最后把滚动轮播图片的mui(".mui-slider").slider({interval: 300 ...
- SwipeRefreshLayout实现下拉刷新上滑加载
1. 效果图 2.RefreshLayout.java package myapplication.com.myapplication; import android.content.Context; ...
- 微信小程序下拉刷新 并重新加载数据
1.在json页面配置: { "enablePullDownRefresh": true } 2.调用刷新函数 onPullDownRefresh: function() { wx ...
- Android 下拉刷新上啦加载SmartRefreshLayout + RecyclerView
在弄android刷新的时候,可算是耗费了一番功夫,最后发觉有现成的控件,并且非常好用,这里记录一下. 原文是 https://blog.csdn.net/huangxin112/article/de ...
- juery下拉刷新,div加载更多元素并添加点击事件(二)
buffer.append("<div class='col-xs-3 "+companyId+"' style='padding-left: 10px; padd ...
随机推荐
- AtCoder Regular Contest 080 E:Young Maids
题目传送门:https://arc080.contest.atcoder.jp/tasks/arc080_c 题目翻译 给你一个\(n\)的排列\(p\),一个空序列\(q\),你每次可以从\(p\) ...
- MQTT协议简介及协议原理
MQTT(Message Queuing Telemetry Transport,消息队列遥测传输协议),是一种基于发布/订阅(publish/subscribe)模式的“轻量级”通讯协议,该协议构建 ...
- MSTAR 平台
MApp_Menu.c ZUI_exefunc.h //菜单属性 MApp_ZUI_APItables.h #define GETWNDINFO(hwnd) (&g_GUI_WindowLis ...
- 开源监控系统中 Zabbix 和 Nagios 哪个更好?
监控平台的话,各有优劣,但基本都可以满足需求.等达到一定监控指标后,发现,最困难的是监控项目的管理. CMDB中小规模(服务器<=1k):Zabbix大规模(1k>=服务器<=10k ...
- rmmod: chdir(/lib/modules): No such file or directory
内核版本:linux3.4.20 交叉编译器:arm-linux-gcc 4.3.3 busybox : busybox 1.20 问题: 使用rmmod会出现 rmmod : chdir(/lib ...
- jmeter设置默认为中文
1.编辑jmeter目录/bin/jmeter.porperties文件 2.点击将language的注释去掉,并将值变为zh_CN保存.
- stm32之通信
本文提到的内容有以下几个方面: 通信概述 串口通信 I2C通信 CAN通信 SPI通信 I2S通信 USB通信 其他通信 一.通信概述 按照数据传送方式分: 串行通信(一条数据线.适合远距离传输.控制 ...
- [cf2015ICLFinalsDiv1J]Ceizenpok’s formula
题意:$C_n^m\% k$ 解题关键:扩展lucas+中国剩余定理裸题 #include<algorithm> #include<iostream> #include< ...
- glib 库 hash table 使用
glib库提供了 hashtable 的实现 1. 常用函数: 创建一个 GHashTable 函数: hash_func 是创建value的key值的函数,key_equal_func 是比较两个k ...
- Spring入门第十八课
Spring AOP AspectJ:Java社区里最完整最流行的AOP框架 在Spring2.0以上的版本中,可以使用基于AspectJ注解或者基于XML配置的AOP 看代码: package lo ...