一个简单的适用于Vue的下拉刷新,触底加载组件
话不多说,直接上代码,原文地址 博客地址
<template><div class="list-warp-template"@touchstart="handlerStart"@touchend="handlerEnd"@touchmove="handlerMove"@scroll="handlerScroll"ref="listWrapRef"><div class="top-refresh" :style="{height: refresh.height + 'px'}"><div v-show="refresh.height > 30">{{refreshLoading ? '刷新中' : '松开刷新'}}</div></div><div class="main-list"><slot></slot></div><div class="bottom-loading" v-show="bottomLoading">加载中</div></div>
</template>
<script>let timer = nullexport default {name: "ListWrap",props: {refreshLoading: {type: Boolean,default: false}},data() {return {position: 0,startInit: 0,bottomLoading: false,refresh: {height: 0}}},created() {},watch: {refreshLoading(val) {if (!val) {this.refresh.height = 0}}},computed: {},mounted() {},methods: {handlerScroll(e) {const eDom = e.targetconst scrollTop = e.target.scrollTop// 判断是否到底了let scrollPosition = eDom.scrollHeight - e.target.offsetHeightif (timer) {clearTimeout(timer)}// console.log(scrollPosition)// console.log(scrollTop)timer = setTimeout(() => {this.bottomLoading = trueif (scrollPosition <= scrollTop) {this.$emit('on-bottom')}}, 200)this.position = scrollTop// 滚动事件,返回当前滚动位置this.$emit('on-scroll', scrollPosition)},// 返回顶部handlerBackTop() {const dom = this.$refs.listWrapRefdom.scrollTop = 0},// 触摸开始handlerStart(e) {this.startInit = parseInt(e.touches[0].clientY)},// 滑动中,下拉handlerMove(e) {if (this.position === 0 && !this.refreshLoading) {const Y = parseInt(e.touches[0].clientY)const range = Y - this.startInitthis.refresh.height = range}},// 滑动结束handlerEnd() {if (this.refresh.height >= 30) {this.refresh.height = 40this.$emit('on-refresh')this.$emit('update:refreshLoading', true)} else {this.refresh.height = 0}this.startInit = 0}}}
</script>
<style lang="scss">.list-warp-template {display: block;height: 100vh;overflow-y: auto;.top-refresh {background-color: #ccc;height: 0;width: 100%;transition: height 0.1s linear;overflow: hidden;color: #fff;display: flex;align-items: center;justify-content: center;}.main-list {width: 100%;}.bottom-loading {height: 40px;display: flex;align-items: center;justify-content: center;color: #999;width: 100%;background-color: #f0f0f0;}}
</style>
复制代码
一个简单的适用于Vue的下拉刷新,触底加载组件相关推荐
- uni-app下拉刷新触底加载更多
首先在pages.json 配置文件中配置 "enablePullDownRefresh": true 需要在哪用加载就配置在路由的style里 两个事件 //下拉刷新 o ...
- Vue 下拉刷新及无限加载组件 - 有你便是晴天 - 博客园
原文 https://github.com/wangdahoo/vue-scroller 主题 Vue.js Vue Scroller Vue Scroller is a foundational ...
- (仿头条APP项目)6.点击过的新闻列表文字变灰和下拉刷新与滚动加载新闻数据
文章目录 一.点击过的新闻列表文字变灰 效果图 实现思路 导入ormlite数据库类依赖 利用ormlite创建数据库和表 创建数据库类MyDbHelper 创建数据库中的新闻实体类NewInfo 页 ...
- recyclerview的数据刷新(下拉刷新和自动加载更多)以及添加提示语(例如:“数据已加载完毕”)
下拉加载更多的核心是SwipeRefreshLayout搭配Recyclerview进行使用.布局为 <android.support.v4.widget.SwipeRefreshLayout ...
- 微信小程序04---头像上传、瀑布流、下拉刷新、触底加载更多、分包
目录 一.头像上传 1.选择图片 wx.chooseImage() 2.上传文件 wx.uploadFile() 二.瀑布流+下拉刷新+触底加载 三.分包加载 什么是分包 为什么要使用分包 如 ...
- Vue 列表 懒加载 触底加载
一.方法一 描述:列表懒加载+节流 效果图: 实现: 组件:LazyLoading <template><div class="lazy-list">< ...
- 小程序 下拉刷新 上拉触底加载数据
1. 下拉刷新 下拉刷新主要用到「onPullDownRefresh」函数,我们在新建目录然后新建page之后在wxml文件中会自动生成很多生命周期函数,其中就会生成「onPullDownRefres ...
- Vue实现下拉刷新组件(简单明了)
笔者在写这篇文章时,刚刚完成了下拉组件的封装,还热乎着.迫不及待的想分享给大家.在这之前,如果你跟我一样带着些迷惑和好奇,想要自己动手完成一些框架中的组件并了解其原理.希望这篇文章可以帮到你. 一.首 ...
- android中上拉下滑布局,3年以上勿进!最简单的Android自定义ListView下拉刷新与上拉加载,代码直接拿去用~...
本文主要针对开发新手,手写实现一个最简单Android自定义listview下拉刷新和上拉加载demo. 不喜可喷,欢迎大佬留言指点. 效果图 一:编写需要在ListView中增加头加载的布局文件,与 ...
最新文章
- 重磅 | 2018年清华大学研究生新生大数据
- “厌氧动物”出现,科学家不清楚代谢方式,或颠覆对生命的认知
- 关于Windows Vista的系统修复
- html下拉列表框设置两个,怎么使用HTML option标签添加两个value
- Java设计模式百例(番外) - Java的clone
- C++内联函数的学习
- nginx源码分析—内存池结构ngx_pool_t及内存管理(精辟)
- 抖音gorgon算法04php,抖音xgorgon(0401)获取方法及演示
- LeetCode 120. 三角形最小路径和
- DenseNet细节
- 点4下还是点1下?使用jQuery启动一个SharePoint工作流
- python列表获取最后一个元素的方法_Python中如何获取 list/OrderedDict 的 第一个/最后一个 元素...
- 【Practical】决策系统与粗糙集
- 有趣的python小程序(附效果和程序)
- Unity3d 微信小程序(小游戏)项目实现流量主接入功能(含源码)
- Troubleshooting Office Web Apps with SharePoint 2013
- java中的类可以有多个直接父类_一个java类可以有多个父类吗?
- Docker网络 docker network
- WanAndroid,一款每日推荐优质文章App
- Logger日志级别说明及设置方法、说明