主要思路通过自定义指令,在视图初始化完成后,绑定scroll事件。当scrollTop + clientHeight >= scrollHeight时(此时滚定条到了底部)触发loadMore事件,

<template>
<div class="index" v-scroll="loadMore">
<!-- 列表数据传递给子组件,loading表示是否正在加载数据,避免在请求时多次触发 -->
<my-item :lists="lists" :loading="loading" />
</div>
</template> <script>
import MyItem from '~/components/Item.vue'
export default {
name: 'Index',
created () {
// 初始化数据
this.$store.dispatch('GET_INDEX_LISTS')
this.lists = this.$store.state.lists
},
data() {
return {
lists: [],
page: 1,
loading: false
}
},
directives: {
scroll: {
bind: function (el, binding){
window.addEventListener('scroll', function() {
if(document.documentElement.scrollTop + document.documentElement.clientHeight >= document.documentElement.scrollHeight) {
let loadData = binding.value
loadData()
}
})
}
}
},
methods: {
async loadMore(){
if(!this.loading){
this.loading = true
// 请求下一页数据
await this.$store.dispatch('GET_INDEX_LISTS', {
page: this.page++
})
// 重新填充数据
this.lists = this.lists.concat(this.$store.state.lists)
this.loading = false
}
}
},
components: {
MyItem
}
}
</script>

附上一个css loading动画 , Loading.vue:

<template>
<div class="loading">
<div class="loader-inner line-scale">
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</div>
</div>
</template>
<style>
.loading {
text-align: center;
}
.loader-inner {
display: inline-block;
} @-webkit-keyframes line-scale {
0% {
-webkit-transform: scaley(1);
transform: scaley(1);
} 50% {
-webkit-transform: scaley(0.4);
transform: scaley(0.4);
} 100% {
-webkit-transform: scaley(1);
transform: scaley(1);
}
} @keyframes line-scale {
0% {
-webkit-transform: scaley(1);
transform: scaley(1);
} 50% {
-webkit-transform: scaley(0.4);
transform: scaley(0.4);
} 100% {
-webkit-transform: scaley(1);
transform: scaley(1);
}
} .line-scale > div:nth-child(1) {
-webkit-animation: line-scale 1s 0.1s infinite
cubic-bezier(0.2, 0.68, 0.18, 1.08);
animation: line-scale 1s 0.1s infinite cubic-bezier(0.2, 0.68, 0.18, 1.08);
} .line-scale > div:nth-child(2) {
-webkit-animation: line-scale 1s 0.2s infinite
cubic-bezier(0.2, 0.68, 0.18, 1.08);
animation: line-scale 1s 0.2s infinite cubic-bezier(0.2, 0.68, 0.18, 1.08);
} .line-scale > div:nth-child(3) {
![](http://images2017.cnblogs.com/blog/1027889/201712/1027889-20171206110307066-486062764.png) -webkit-animation: line-scale 1s 0.3s infinite
cubic-bezier(0.2, 0.68, 0.18, 1.08);
animation: line-scale 1s 0.3s infinite cubic-bezier(0.2, 0.68, 0.18, 1.08);
} .line-scale > div:nth-child(4) {
-webkit-animation: line-scale 1s 0.4s infinite
cubic-bezier(0.2, 0.68, 0.18, 1.08);
animation: line-scale 1s 0.4s infinite cubic-bezier(0.2, 0.68, 0.18, 1.08);
} .line-scale > div:nth-child(5) {
-webkit-animation: line-scale 1s 0.5s infinite
cubic-bezier(0.2, 0.68, 0.18, 1.08);
animation: line-scale 1s 0.5s infinite cubic-bezier(0.2, 0.68, 0.18, 1.08);
} .line-scale > div {
background-color: #fe0061;
width: 4px;
height: 30px;
border-radius: 2px;
margin: 2px;
-webkit-animation-fill-mode: both;
animation-fill-mode: both;
display: inline-block;
}
</style>

加载效果图:

vue实现pc端无限加载功能的更多相关文章

  1. Vue中实现一个无限加载列表

    参考 https://www.jianshu.com/p/0a3aebd63a14 一个需要判断的地方就是加载中再次触发滚动的时候,不要获取数据. <!DOCTYPE html> < ...

  2. js实现移动端无限加载分页

    原理:当滚动条到达底部时,执行下一页内容. 判断条件需要理解三个概念:    1.scrollHeight 真实内容的高度    2.clientHeight 视窗的高度,即在浏览器中所能看到的内容的 ...

  3. Vue.js 开发实践:实现精巧的无限加载与分页功能

    本篇文章是一篇Vue.js的教程,目标在于用一种常见的业务场景--分页/无限加载,帮助读者更好的理解Vue.js中的一些设计思想.与许多Todo List类的入门教程相比,更全面的展示使用Vue.js ...

  4. vux-scroller实现移动端上拉加载功能

    本文将讲述vue-cli+vux-scroller实现移动端的上拉加载功能: 纠错声明:网上查阅资料看到很多人都将vux和vuex弄混,在这里我们先解释一下,vuex是vue框架自带的组件,是数据状态 ...

  5. 使用scrollpagination实现页面底端自动加载无需翻页功能

    当阅读到页面最底端的时候,会自动显示一个"加载中"的功能,并自动从服务器端无刷新的将内容下载到本地浏览器显示. 这样的自动加载功能是如何实现的?jQuery的插件 ScrollPa ...

  6. Qt实现小功能之列表无限加载

    概念介绍 无限加载与瀑布流的结合在Web前端开发中的效果非常新颖,对于网页内容具备较好的表现形式.无限加载并没有一次性将内容全部加载进来,而是通过监听滚动条事件来刷新内容的.当用户往下拖动滚动条或使用 ...

  7. Qt实现小功能之列表无限加载(创意很不错:监听滚动条事件,到底部的时候再new QListWidgetItem)

    概念介绍 无限加载与瀑布流的结合在Web前端开发中的效果非常新颖,对于网页内容具备较好的表现形式.无限加载并没有一次性将内容全部加载进来,而是通过监听滚动条事件来刷新内容的.当用户往下拖动滚动条或使用 ...

  8. JRoll 2 使用文档(史上最强大的下拉刷新,滚动,无限加载插件)

    概述 说明 JRoll,一款能滚起上万条数据,具有滑动加速.回弹.缩放.滚动条.滑动事件等功能,兼容CommonJS/AMD/CMD模块规范,开源,免费的轻量级html5滚动插件. JRoll第二版是 ...

  9. JS实现-页面数据无限加载

    在手机端浏览网页时,经常使用一个功能,当我们浏览京东或者淘宝时,页面滑动到底部,我们看到数据自动加载到列表.之前并不知道这些功能是怎么实现的,于是自己在PC浏览器上模拟实现这样的功能.先看看浏览效果: ...

随机推荐

  1. AnjularJS表单回车提交事件

    问题: 输入手机号之后,再验证码输入框点击回车时,触发发送验证码事件. <div class="login-main"> <form name="log ...

  2. 如何实现CSS限制字数,超出部份显示点点点...

    <div style="width:200px; white-space:nowrap;overflow:hidden;text-overflow:ellipsis; border:1 ...

  3. android面试题总结加强再加强版(一)

    在加强版的基础上又再加强的android应用面试题集 有些补充略显臃肿,只为学习 1.activity的生命周期. 方法 描述 可被杀死 下一个 onCreate() 在activity第一次被创建的 ...

  4. ASP.NET C# 实现钉钉签名算法

    在 https://open-doc.dingtalk.com/microapp/faquestions/hxs5v9 钉钉给出了JAVA/PHP算法,下面是C#算法 using System.Sec ...

  5. CSS实现16:9等比例盒子

    问题:图片的宽度100%,高度要始终自适应为16:9. 解决方案: 1.通过js程序算出绝对高度再进行设置.这是解决问题最容易想到的方法. 2.但是,我们的原则是能用css实现的功能尽量用css,这有 ...

  6. linux-网站收藏

    创建sudo无密码登陆 http://www.aboutyun.com/blog-61-428.html

  7. mysql YEARWEEK(date[,mode]) 函数 查询上周数据 以及本周数据

    通常使用下边sql即可(如果数据库设置了周一为一周起始的话):  查询上周数据(addtime为datetime格式)  SELECT id,addtime FROM mall_order WHERE ...

  8. FFM及DeepFFM模型在推荐系统的探索及实践

    12月20日至23日,全球人工智能与机器学习技术大会 AiCon 2018 在北京国际会议中心盛大举行,新浪微博AI Lab 的资深算法专家 张俊林@张俊林say 主持了大会的 搜索推荐与算法专题,并 ...

  9. python接口自动化测试(七)-unittest-批量用例管理

    我们日常项目中的接口测试案例肯定不止一个,当案例越来越多时我们如何管理这些批量案例?如何保证案例不重复?如果案例非常多(成百上千,甚至更多)时如何保证案例执行的效率?如何做(批量)测试数据的管理?如何 ...

  10. Java虚拟机垃圾回收:内存分配与回收策略 方法区垃圾回收 以及 JVM垃圾回收的调优方法

    在<Java对象在Java虚拟机中的创建过程>了解到对象创建的内存分配,在<Java内存区域 JVM运行时数据区>中了解到各数据区有些什么特点.以及相关参数的调整,在<J ...