vue2.0移动端做出下拉刷新与上拉加载功能

这次给大家带来vue2.0移动端做出下拉刷新与上拉加载功能,vue2.0移动端做出下拉刷新与上拉加载功能的注意事项有哪些,下面就是实战案例,一起来看一下。

直接上代码,不懂的多看几遍,下面我换会告诉大家如何使用。

 

下拉更新 松开更新 更新中
加载中……

export default { props: { offset: { type: Number, default: 40 }, 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 }, 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() } }}.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;}

登录后复制

把上面组件拷贝一下,存成后缀是.vue的组件放到你的component下,  然后引入到页面 , 下面是我引用的demo

上代码: 里面有注释哦,有问题给我留言!

 

  • {{item.name}}
  • {{item.name}}

import Scroll from './y-scroll/scroll';export default{ data () { return { counter : 1, //默认已经显示出15条数据 count等于一是让从16条开始加载 num : 15, // 一次显示多少条 pageStart : 0, // 开始页数 pageEnd : 0, // 结束页数 listdata: [], // 下拉更新数据存放数组 downdata: [] // 上拉更多的数据存放数组 } }, mounted : function(){ this.getList(); }, methods: { getList(){ let vm = this; vm.$http.get('https://api.github.com/repos/typecho-fans/plugins/contents/').then((response) => { vm.listdata = response.data.slice(0,15); }, (response) => { console.log('error'); }); }, onRefresh(done) { this.getList(); done() // call done }, onInfinite(done) { let vm = this; vm.$http.get('https://api.github.com/repos/typecho-fans/plugins/contents/').then((response) => { vm.counter++; vm.pageEnd = vm.num * vm.counter; vm.pageStart = vm.pageEnd - vm.num; let arr = response.data; let i = vm.pageStart; let end = vm.pageEnd; for(; i= response.data.length){ this.$el.querySelector('.load-more').style.display = 'none'; return; } } done() // call done }, (response) => { console.log('error'); }); } }, components : {'v-scroll': Scroll }}

登录后复制

相信看了本文案例你已经掌握了方法,更多精彩请关注【创想鸟】其它相关文章!

推荐阅读:

Vue在前端开发中需要注意什么

vue.js怎么做出登录控制功能

以上就是vue2.0移动端做出下拉刷新与上拉加载功能的详细内容,更多请关注【创想鸟】其它相关文章!

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至253000106@qq.com举报,一经查实,本站将立刻删除。

发布者:PHP中文网,转转请注明出处:https://www.chuangxiangniao.com/p/2767207.html

(0)
上一篇 2025年3月8日 11:32:37
下一篇 2025年3月7日 18:21:41

AD推荐 黄金广告位招租... 更多推荐

相关推荐

  • vue移动端实现下拉刷新步骤详解

    这次给大家带来vue移动端实现下拉刷新步骤详解,vue移动端实现下拉刷新的注意事项有哪些,下面就是实战案例,一起来看一下。 看完这篇文章,相信大伙也一样可以,做出一个自己的刷新,加载的组件 说这个功能之前,大家要先了解一下,要怎么触发滚动条…

    2025年3月8日
    100
  • Vue实现不刷新分页

    这次给大家带来Vue实现不刷新分页,Vue实现不刷新分页的注意事项有哪些,下面就是实战案例,一起来看一下。 之前一直想要自己试着实现一个分页器,但是一直拖,今天写完,大概照着网易云音乐的样子来完成。这个小例子很简单,通过这个小例子,可以学习…

    2025年3月8日 编程技术
    200
  • 怎么阻止vuex页面刷新后数据清除

    这次给大家带来怎么阻止vuex页面刷新后数据清除,阻止vuex页面刷新后数据清除的注意事项有哪些,下面就是实战案例,一起来看一下。 1.原因 2.解决方法 localStorage没有时间期限,除非将它移除,sessionStorage即会…

    2025年3月8日
    200
  • 如何让Vue2.0做出单选互斥

    这次给大家带来如何让Vue2.0做出单选互斥,Vue2.0做出单选互斥的注意事项有哪些,下面就是实战案例,一起来看一下。 本文介绍了Vue2.0 实现单选互斥的方法,分享给大家,具体如下: 需要实现如上图的功能 1. 首次加载页面,根据da…

    2025年3月8日
    200
  • vue2.0选中active后其他选项互斥实现步骤

    这次给大家带来vue2.0选中active后其他选项互斥实现步骤,vue2.0选中active后其他选项互斥的注意事项有哪些,下面就是实战案例,一起来看一下。 在正常的js中。我们如果要实现点击选中active然后其他取消的效果,我们可以定…

    2025年3月8日
    200
  • vue2.0实现注册登录步骤详解

    这次给大家带来vue2.0实现注册登录步骤详解,vue2.0实现注册登录的注意事项有哪些,下面就是实战案例,一起来看一下。 前言 前段时间和公司一个由技术转产品的同事探讨他的职业道路,对我说了一句深以为然的话: “不要把自己禁锢在某一个领域…

    2025年3月8日
    200
  • vue2.0资源文件assets和static使用说明

    这次给大家带来vue2.0资源文件assets和static使用说明,vue2.0资源文件assets和static使用的注意事项有哪些,下面就是实战案例,一起来看一下。 资源文件处理 在我们的项目结构里,有两个资源文件的路径,分别是:sr…

    编程技术 2025年3月8日
    200
  • 在bootstrap中使用selectpicker实现下拉框

    这次给大家带来在bootstrap中使用selectpicker实现下拉框,在bootstrap中使用selectpicker实现下拉框的bootstrap有哪些,下面就是实战案例,一起来看一下。 前言 最近一直在用bootstrap 的一…

    2025年3月8日
    200
  • Vue实现动态刷新Echarts组件

    这次给大家带来Vue实现动态刷新Echarts组件,Vue实现动态刷新Echarts组件的注意事项有哪些,下面就是实战案例,一起来看一下。 需求背景:dashboard作为目前企业中后台产品的“门面”,如何更加实时、高效、炫酷的对统计数据进…

    2025年3月8日
    200
  • 在移动端mint-ui loadmore实现下拉刷新上拉显示更多

    这次给大家带来在移动端mint-ui loadmore实现下拉刷新上拉显示更多,在移动端mint-ui loadmore实现下拉刷新上拉显示更多的注意事项有哪些,下面就是实战案例,一起来看一下。 mintui是饿了么团队针对vue开发的移动…

    编程技术 2025年3月8日
    200

发表回复

登录后才能评论