vue2.0 移动端,下拉刷新,上拉加载更多插件,修改版

时间:2022-09-19 23:15:12

在【实现丰盛】的插件基础修改【vue2.0 移动端,下拉刷新,上拉加载更多 插件】,

1.修改加载到尾页面,返回顶部刷新数据,无法继续加重下一页

2.修改加载完成文字提示

原文链接:http://www.cnblogs.com/sichaoyun/p/6647458.html

<template lang="html">
<div class="yo-scroll"
:class="{'down':(state===0),'up':(state==1),refresh:(state===2),touch:touching}"
@touchstart="touchStart($event)"
@touchmove="touchMove($event)"
@touchend="touchEnd($event)"
@scroll="(onInfinite || infiniteLoading) ? onScroll($event) : undefined">
<section class="inner" :style="{ transform: 'translate3d(0, ' + top + 'px, 0)' }">
<header class="pull-refresh">
<slot name="pull-refresh">
<span class="down-tip">下拉更新</span>
<span class="up-tip">松开更新</span>
<span class="refresh-tip">更新中……</span>
</slot>
</header>
<slot></slot>
<footer class="load-more">
<slot name="load-more">
<span>{{loadingText}}</span>
</slot>
</footer>
</section>
</div>
</template> <script>
export default {
props: {
offset: {
type: Number,
default: 40
},
loadingText: {
type: String,
default: '加载中...'
},
enableInfinite: {
type: Boolean,
default: true
},
enableRefresh: {
type: Boolean,
default: true
},
onRefresh: {
type: Function,
default: undefined,
required: false
},
onInfinite: {
type: Function,
default: undefined,
require: false
}
},
data() {
return {
top: 0,
state: 0,
startY: 0,
touching: false,
infiniteLoading: false
}
},
methods: {
touchStart(e) {
this.startY = e.targetTouches[0].pageY
this.startScroll = this.$el.scrollTop || 0
this.touching = true
},
touchMove(e) {
if (!this.enableRefresh || this.$el.scrollTop > 0 || !this.touching) {
return
}
let diff = e.targetTouches[0].pageY - this.startY - this.startScroll
if (diff > 0) e.preventDefault()
this.top = Math.pow(diff, 0.8) + (this.state === 2 ? this.offset : 0) if (this.state === 2) { // in refreshing
return
}
if (this.top >= this.offset) {
this.state = 1
} else {
this.state = 0
}
},
touchEnd(e) {
if (!this.enableRefresh) return
this.touching = false
if (this.state === 2) { // in refreshing
this.state = 2
this.top = this.offset
return
}
if (this.top >= this.offset) { // do refresh
this.refresh()
} else { // cancel refresh
this.state = 0
this.top = 0
}
},
refresh() {
this.state = 2
this.top = this.offset
this.onRefresh(this.refreshDone)
},
refreshDone() {
this.state = 0
this.top = 0
this.infiniteLoading = false
}, infinite() {
this.infiniteLoading = true
this.onInfinite(this.infiniteDone)
}, infiniteDone() {
this.infiniteLoading = false
}, onScroll(e) {
if (!this.enableInfinite || this.infiniteLoading) {
return
}
let outerHeight = this.$el.clientHeight
let innerHeight = this.$el.querySelector('.inner').clientHeight
let scrollTop = this.$el.scrollTop
let ptrHeight = this.onRefresh ? this.$el.querySelector('.pull-refresh').clientHeight : 0
let infiniteHeight = this.$el.querySelector('.load-more').clientHeight
let bottom = innerHeight - outerHeight - scrollTop - ptrHeight
if (bottom < infiniteHeight) this.infinite()
}
}
}
</script>
<style>
.yo-scroll {
position: absolute;
top: 2.5rem;
right: 0;
bottom: 0;
left: 0;
overflow: auto;
-webkit-overflow-scrolling: touch;
background-color: #ddd
}
.yo-scroll .inner {
position: absolute;
top: -2rem;
width: 100%;
transition-duration: 300ms;
}
.yo-scroll .pull-refresh {
position: relative;
left: 0;
top: 0;
width: 100%;
height: 2rem;
display: flex;
align-items: center;
justify-content: center;
}
.yo-scroll.touch .inner {
transition-duration: 0ms;
}
.yo-scroll.down .down-tip {
display: block;
}
.yo-scroll.up .up-tip {
display: block;
}
.yo-scroll.refresh .refresh-tip {
display: block;
}
.yo-scroll .down-tip,
.yo-scroll .refresh-tip,
.yo-scroll .up-tip {
display: none;
}
.yo-scroll .load-more {
height: 3rem;
display: flex;
align-items: center;
justify-content: center;
}
</style>

  把上面组件拷贝一下,保存vue文件pull-refresh.vue放到你的component/common文件夹下,  然后引入到页面 , 下面是引用demo

<template>
<div class="home"> <v-scroll :on-refresh="onRefresh" :on-infinite="onInfinite" :loading-text="loadingText" >
<ul class="list">
<li v-for="item in articleList">{{item.title}}</li>
</ul>
</v-scroll>
</div>
</template> <script>
import { AjaxPlugin, XButton,Group, Cell, XInput} from 'vux'
import Scroll from '../../common/pull-refresh'; export default {
name: 'home',
components: {
'v-scroll': Scroll,
Group,
XButton,
Cell,
XInput,
AjaxPlugin
},
data () {
return {
articleList:this.getArticleList(1),
loadingText:'加载中...',
counter : 1, //当前页面
num : 20, // 一次显示多少条
listdata: [], // 下拉更新数据存放数组
downdata: [] // 上拉更多的数据存放数组
}
},
mounted : function(){
//this.getArticleList();
},
methods: { getArticleList: function (catId) {
let _this = this
getDate('/index.php',{params:{m:'jsonp',c:'index',a:'lists',catid:59}},function(data){
let arr = data.result.data;
_this.articleList=arr;
if(arr.length>=_this.num){
_this.counter++;
}
})
return []
},
onRefresh(done) {
let vm = this;
vm.loadingText='加载中……';
getDate('/index.php',{params:{m:'jsonp',c:'index',a:'lists',catid:59}},function(data){
let arr = data.result.data;
vm.articleList=arr;
if(arr.length>=vm.num){
vm.counter=2;
}
done() // call done
})
},
onInfinite(done) {
let vm = this;
getDate('/index.php',{params:{m:'jsonp',c:'index',a:'lists',catid:59,page:vm.counter}},function(data){
let arr = data.result.data;
vm.articleList=vm.articleList.concat(arr);
if(arr.length<vm.num){
vm.loadingText='加载完毕……';
//vm.$el.querySelector('.load-more').style.display = 'none';
return;
}else{
vm.counter++;
}
done() // call done
})
}
}
} function getDate(url,params,fn) {
AjaxPlugin.$http.get(url, params)
.then((response) => {
if (fn) fn(response.data)
}) } function htttpRequest (url, params, cb) {
let dataStr = ''
for (let key in params) {
dataStr += key + '=' + params[key]
} dataStr = dataStr.substr(0, dataStr.length - 1)
console.log(dataStr);
AjaxPlugin.$http.post(url, params)
.then((response) => {
if (cb) cb(response.data)
})
} </script> <!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
h1, h2 {
font-weight: normal;
} ul {
list-style-type: none;
padding: 0;
} li {
flex: 1;
margin: 10px ;
border-bottom:#ddd solid 1px;
} a {
color: #42b983;
}
</style>

  

vue2.0 移动端,下拉刷新,上拉加载更多插件,修改版的更多相关文章

  1. SwipeRefreshLayout实现下拉刷新上滑加载

    1. 效果图 2.RefreshLayout.java package myapplication.com.myapplication; import android.content.Context; ...

  2. Android 下拉刷新上啦加载SmartRefreshLayout &plus; RecyclerView

    在弄android刷新的时候,可算是耗费了一番功夫,最后发觉有现成的控件,并且非常好用,这里记录一下. 原文是 https://blog.csdn.net/huangxin112/article/de ...

  3. juery下拉刷新,div加载更多元素并添加点击事件&lpar;二&rpar;

    buffer.append("<div class='col-xs-3 "+companyId+"' style='padding-left: 10px; padd ...

  4. 移动端下拉刷新上拉加载-mescroll&period;js插件

    最近无意间看到有这么一个上拉刷新下拉加载的插件 -- mescroll.js,个人感觉挺好用的,官网地址是:http://www.mescroll.com 然后我就看了一下文档,简单的写了一个小dem ...

  5. Android如何定制一个下拉刷新,上滑加载更多的容器

    前言 下拉刷新和上滑加载更多,是一种比较常用的列表数据交互方式. android提供了原生的下拉刷新容器 SwipeRefreshLayout,可惜样式不能定制. 于是打算自己实现一个专用的.但是下拉 ...

  6. Android 自定义 ListView 上下拉动&ldquo&semi;刷新最新&rdquo&semi;和&ldquo&semi;加载更多&rdquo&semi;歌曲列表

    本文内容 环境 测试数据 项目结构 演示 参考资料 本文演示,上拉刷新最新的歌曲列表,和下拉加载更多的歌曲列表.所谓"刷新最新"和"加载更多"是指日期.演示代码 ...

  7. 基于SwiperJs的H5&sol;移动端下拉刷新上拉加载更多的效果

    最早时,公司的H5项目中曾用过点击一个"加载更多"的DOM元素来实现分页的功能,后来又用过网上有人写的一个上拉加载更多的插件,那个插件是页面将要滚动到底部时就自动请求数据并插入到页 ...

  8. 基于SwiperJs的H5&sol;移动端下拉刷新上拉加载更多

    最早时,公司的H5项目中曾用过点击一个"加载更多"的DOM元素来实现分页的功能,后来又用过网上有人写的一个上拉加载更多的插件,那个插件是页面将要滚动到底部时就自动请求数据并插入到页 ...

  9. 【Web】移动端下拉刷新、上拉加载更多插件

    移动网站中常常有的功能:列表的下拉刷新.上拉加载更多 本例介绍一种简单使用的移动端下拉刷新.上拉加载更多插件,下载及参考地址:https://github.com/ximan/dropload 插件依 ...

随机推荐

  1. 您试图在此 Web 服务器*问的 Web 应用程序当前不可用

    错误提示: 服务器应用程序不可用 您试图在此 Web 服务器*问的 Web 应用程序当前不可用.请点击 Web 浏览器中的“刷新”按钮重试您的请求. 管理员注意事项: 详述此特定请求失败原因的错误信 ...

  2. CentOS安装JAVA后JAVA版本不对的问题

    今天用CentOS安装JDK,发觉在安装完成后,输入java命令来验证是否安装成功时,出现 Usage: gij [OPTION] ... CLASS [ARGS] ...          to i ...

  3. Nginx加多个tomcat实现负载均衡,动静分离

    一:Nginx+Tomcat的动静分离 所谓动静分离就是通过nginx(或apache等)来处理用户端请求的图片.html等静态的文件,tomcat(或weblogic)处理jsp.do等动态文件,从 ...

  4. CentOS 6&period;7增加SWAP交换分区

    任务:新增一个1GB的SWAP分区,并开机自动挂载 1.在/var目录下新增SWAPFILE交换区文件 2.生成SWAP分区 mkswap /var/SWAPFILE 3.激活SWAP分区 swapo ...

  5. &lpar;转&rpar;JAVA堆栈操作

    java.util.Queue用法(是util中的一个接口) 队列是一种特殊的线性表,它只允许在表的前端(front)进行删除操作,而在表的后端(rear)进行插入操作.进行插入操作的端称为队尾,进行 ...

  6. 使用Angular cli创建组件报错: Unexpected token &sol; in JSON at position&period;&period;&period;&period;

    之前为了熟悉流程一直都是手动创建组件,今天试着用cli创建组件,居然报错了,报错大致为: Unexpected token / in JSON at position.... ,并且错误指向了.ang ...

  7. drawImg、x5浏览器、react

  8. Python-多表关联 外键 级联

    分表为什么分表 多表关联多表关系 ****** 表之间的关系 为什么要分表 多对一 一个外键 多对多 一个中间表 两个外键 一对一 一个外键加一个唯一约束外键约束 ****** foreign key ...

  9. 离线环境下安装ansible,借助有网环境下pip工具

    环境 有网的机器(192.168.19.222):rhe65,python2.7.13,pip9.0.1 离线机器(192.168.19.203):rhe65,python2.6 FTP(192.16 ...

  10. postgresql----Gist索引

    GiST的意思是通用的搜索树(Generalized Search Tree). 它是一种平衡树结构的访问方法,在系统中作为一个基本模版,可以使用它实现任意索引模式.B-trees, R-trees和 ...