一个简单的适用于Vue的上拉刷新,触底加载组件,没有发布npm需要时直接粘贴定制修改即可

<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 = null
export 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.target
const scrollTop = e.target.scrollTop
// 判断是否到底了
let scrollPosition = eDom.scrollHeight - e.target.offsetHeight
if (timer) {
clearTimeout(timer)
}
// console.log(scrollPosition)
// console.log(scrollTop)
timer = setTimeout(() => {
this.bottomLoading = true
if (scrollPosition <= scrollTop) {
this.$emit('on-bottom')
}
}, 200)
this.position = scrollTop
// 滚动事件,返回当前滚动位置
this.$emit('on-scroll', scrollPosition)
},
// 返回顶部
handlerBackTop() {
const dom = this.$refs.listWrapRef
dom.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.startInit
this.refresh.height = range
}
},
// 滑动结束
handlerEnd() {
if (this.refresh.height >= 30) {
this.refresh.height = 40
this.$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的下拉刷新,触底加载组件的更多相关文章

  1. el-select实现下拉框触底加载更多

    当下拉框需要展示的数据有很多时,几千甚至上万条,一次性全部请求回来再按照特定格式比如 id-name 去处理数据的话,不论是从接口还是前端,这个性能都不是很好,会造成下拉框初次打开时响应很慢,影响用户 ...

  2. Vue Scroller:Vue 下拉刷新及无限加载组件

    Vue Scroller Vue Scroller is a foundational component ofVonic UI. In purpose of smooth scrolling, pu ...

  3. Vue 下拉刷新及无限加载组件

    原文  https://github.com/wangdahoo/vue-scroller 主题 Vue.js Vue Scroller Vue Scroller is a foundational ...

  4. jQuery WeUI 组件下拉刷新和滚动加载的实现

    最近在做手机版使用到了下拉刷新和滚动加载,记录一下实现过程: 一.引入文件 ? 1 2 3 4 <link rel="stylesheet" href="Conte ...

  5. 第三方 XListview 上拉加载、下拉刷新、分页加载和Gson解析

    注意:此Demo用的是第三方的Xlistview.jar,需要复制me文件夹到项目中,两个XML布局文件和一张图片 把下面的复制到String中 <string name="xlist ...

  6. mui 动态加载数据出现的问题处理 (silder轮播组件 indexedList索引列表 下拉刷新不能继续加载数据)

    mui-slider 问题:动态给mui的图片轮播添加图片,轮播不滚动. 解决:最后把滚动轮播图片的mui(".mui-slider").slider({interval: 300 ...

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

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

  8. 微信小程序下拉刷新 并重新加载数据

    1.在json页面配置: { "enablePullDownRefresh": true } 2.调用刷新函数 onPullDownRefresh: function() { wx ...

  9. Android 下拉刷新上啦加载SmartRefreshLayout + RecyclerView

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

随机推荐

  1. Python3开启Http服务

    在CMD命令行输入D: 切换到D盘, 然后输入 python -m http.server 8000 开启HTTP服务: 在浏览器地址栏输入 http://localhost:8000/

  2. div布局方案整理

    实际项目开发过程中遇到页面 DIV 左右布局的需求:左侧 DIV 固定宽度,右侧 DIV 自适应宽度,填充满剩余页面,由此引申出本文的几种解决方案 1 左侧 DIV 设置 float 属性为 left ...

  3. 第五篇 Flask组件之SQLAchemy及Flask-SQLAlchemy插件/Flask-Script/Flask-migrate/pipreqs模块

    SQLAlchemy组件 一. 介绍 SQLAlchemy是一个基于Python实现的ORM框架.该框架建立在 DB API之上,使用关系对象映射进行数据库操作,简言之便是:将类和对象转换成SQL,然 ...

  4. jmeter使用复习

    多终端进程: 配置客户端远程的ip地址和port 在客户端jmeter安装目录的bin目录下,修改配置文件 jmeter.properties 默认的remote_hosts 的值:(将肉鸡的地址加入 ...

  5. Python3.5 Keras-Theano(含其他库)windows 安装环境

    https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/Anaconda3-4.2.0-Windows-x86.execonda --version ...

  6. vue移动音乐app开发学习(三):轮播图组件的开发

    本系列文章是为了记录学习中的知识点,便于后期自己观看.如果有需要的同学请登录慕课网,找到Vue 2.0 高级实战-开发移动端音乐WebApp进行观看,传送门. 完成后的页面状态以及项目结构如下: 一: ...

  7. c# CLR无法从 COM 上下文 0x51cd20 转换为 COM 上下文 0x51ce90

    调试菜单--->异常---->managed debugging assistants栏下ContextSwitchDeadlock 前面的√去掉

  8. About Dynamic Programming

    Main Point: Dynamic Programming = Divide + Remember + Guess 1. Divide the key is to find the subprob ...

  9. Java中 Auto-boxing/unboxing

    Java 中 Auto-boxing/unboxing 机制,在合适的时机自动打包,解包. 1. 自动将基础类型转换为对象: 2. 自动将对象转换为基础类型: Demo_1: import java. ...

  10. lintcode-153-数字组合 II

    153-数字组合 II 给出一组候选数字(C)和目标数字(T),找出C中所有的组合,使组合中数字的和为T.C中每个数字在每个组合中只能使用一次. 注意事项 所有的数字(包括目标数字)均为正整数. 元素 ...