一个简单的适用于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. spring boot 报错 Error creating bean with name

    Application 启动类 要和父目录平级

  2. git 从头开始

    下载安装git 打开git,输入以下命令,引号内的为你自己的名字和邮箱 git config --global user.name "Your Name"git config -- ...

  3. lintcode142 O(1)时间检测2的幂次

    O(1)时间检测2的幂次 用 O(1) 时间检测整数 n 是否是 2 的幂次. 您在真实的面试中是否遇到过这个题? Yes 样例 n=4,返回 true; n=5,返回 false. 二进制的n中只有 ...

  4. 【Linux 运维】 Centos7.x 系统修复模式

    一.linux的运行级别: 运行级别就是来确定系统启动时到底启动那个服务. linux默认有7个运行级别: 0 关机 1 单用户模式,用于系统修复 2 不完全的命令模式,不含NFS服务 3 完全的命令 ...

  5. puppet学习笔记

    puppet优势:容易理解.用户较多.门槛低.简单.安装配置文件较少 puppet使用Ruby语言开发,安装puppet需要安装Ruby puppet运行环境:Redhat.Centos.Window ...

  6. 2017软工第二次作业 - 本周PSP(补交)

    每周例行报告 1.本周PSP 2. 本周进度条 3.累计进度图 4. 本周PSP饼状图

  7. MyBatis传入参数为list、数组、map写法(转载)

    MyBatis传入参数为list.数组.map写法 1.foreach简单介绍: foreach的主要用在构建in条件中,它可以在SQL语句中进行迭代一个集合. foreach元素的属性主要有item ...

  8. ACM 第六天

    图论 网络流 最大流 INF(初始值) 路径上权值最小的边,决定流量大小. 流量网络的三个特性: ①流量控制 ②反对称性 ③流量守恒 残余网络:保留了c(e)容量<f(e)流量[可以继续流,因为 ...

  9. Thinkphp5的使用phpmailer实现发邮件功能(163邮箱)

    Thinkphp5本身并没有实现发邮件的功能,至少据我所知. 本文利用网易邮箱作为发邮件的邮箱.作为发送邮件的前提是需要开启SMTP服务,打开网易邮件,点击设置按钮,如下图所示 勾选smtp服务 保存 ...

  10. django 使用json.dumps转换queryset的datatime报错问题解决

    最近在使用django做项目的时候想使用ajax来实现前后台数据的交互,但是在将数据库查询结果转换成json数据时,遇到时间格式的数据转换遇到问题,无法正确的进行转换,具体如下: 转换成json时使用 ...