1.创建组件components > zj-roll > index.vue

<template>
<div>
<slot></slot>
<div class='bottom' v-if='(!lastPage.total && lastPage.empty!=0)'>---------- <span >我也是有底线的</span> ----------</div>
<div class='loading' v-if='lastPage.total && lastPage.empty!=0'>
<!-- <img src='@/assets/loading.png' /> -->
玩命加载中</div>
</div>
</template>
<script>
export default {
name: 'scroll',
props: ['lastPage'],
data: function () {
return {
startY: 0,
endY: 0,
initTop: null,
move: 0,
a: 0,
b: 0
}
},
methods: {
getScrollTop () {
let scrollTop = 0
let bodyScrollTop = 0
let documentScrollTop = 0
if (document.body) {
bodyScrollTop = document.body.scrollTop
}
if (document.documentElement) {
documentScrollTop = document.documentElement.scrollTop
}
scrollTop = (bodyScrollTop - documentScrollTop > 0) ? bodyScrollTop : documentScrollTop
return scrollTop
},
// 文档的总高度
getScrollHeight () {
let scrollHeight = 0
let bodyScrollHeight = 0
let documentScrollHeight = 0
if (document.body) {
bodyScrollHeight = document.body.scrollHeight
}
if (document.documentElement) {
documentScrollHeight = document.documentElement.scrollHeight
}
scrollHeight = (bodyScrollHeight - documentScrollHeight > 0) ? bodyScrollHeight : documentScrollHeight
return scrollHeight
},
// 浏览器视口的高度
getWindowHeight () {
var windowHeight = 0
if (document.compatMode === 'CSS1Compat') {
windowHeight = document.documentElement.clientHeight
} else {
windowHeight = document.body.clientHeight
}
return windowHeight
},
handleScroll () {
if (this.getScrollTop() + this.getWindowHeight() === this.getScrollHeight()) {
this.$emit('zj-load')
}
}
},
mounted () {
window.addEventListener('scroll', this.handleScroll)
}
}
</script>
<style lang="less" scoped>
.bottom{
padding:20px 0;
width:100%;
text-align: center;
font-size:16px;
color: #bbb;
span{
margin:0 16px;
}
}
.loading{
padding:20px 0;
text-align: center;
display: flex;
justify-content:center;
align-items: center;
font-size:16px;
color: #bbb;
img{
animation: mymove .5s linear infinite;
width:30px;
height:30px;
margin-right:10px;
}
} @-webkit-keyframes mymove {
0% {transform:rotate(0deg);}
50% {transform:rotate(180deg);}
100% {transform:rotate(360deg);}
} </style>

2.页面中引用组件

<template>
<div class="collection" v-if="show">
<scroll style="position:relative;-webkit-overflow-scrolling : touch;overflow:auto;margin-bottom:45px;" @zj-load="listLoad" :lastPage='{total: !allLoaded, empty: ulList.length}'>
<x-header :left-options="{backText: ''}">我的收藏</x-header> <stopData :ulList="ulList" collection="收藏" v-if="ulList.length > 0"></stopData> <div class="noPoster" v-else>
<div class="font32">
<img src="../../assets/sp_iconx.png"/>暂无收藏~
</div>
</div>
</scroll>
</div>
</template> <script>
import { XHeader } from 'vux'
import stopData from '@/components/stop'
import { collectGoods } from '@/api'
import { timingSafeEqual } from 'crypto';
import { types } from 'util';
import scroll from '@/components/zj-roll' export default {
data () {
return {
ulList: [],
pageSize: 3,
pageIndex: 1,
show: false,
allLoaded: false
}
},
components: {
stopData,
XHeader,
scroll
},
mounted () {
this.defined()
},
methods: {
listLoad(){
let that = this
if (!that.allLoaded) {
that.defined()
}
},
async defined(){
let that = this
    //调取收藏列表数据
const {data} = await collectGoods({pageSize: this.pageSize, pageIndex: this.pageIndex})
if (data.code == 0) {
this.ulList = this.ulList.concat(data.data.page.list)
     // 判断是否还有下一页,如果是pageIndex加一
if (data.data.page.hasNextPage) {
this.allLoaded = false
this.pageIndex = this.pageIndex + 1
} else {
this.allLoaded = true
}
this.show = true
}
},
}
}
</script> <style lang="less">
.collection{
.noPoster{
margin-top: 5.333333rem /* 400/75 */;
display: flex;
justify-content: center;
align-items: center;
color: #999999;
z-index: 0;
background: #ffffff;
div{
display: flex;
align-items: center;
}
img{
width: .746667rem /* 56/75 */;
height: .8rem /* 60/75 */;
margin-right: .32rem /* 24/75 */;
}
}
}
</style>

vue 上拉加载自定义组件,超好用哦的更多相关文章

  1. react-native 自定义 下拉刷新 / 上拉加载更多 组件

    1.封装 Scroller 组件 /** * 下拉刷新/上拉加载更多 组件(Scroller) */ import React, {Component} from 'react'; import { ...

  2. vux, vue上拉加载更多

    <template> <" :bottom-method="loadBottom" :bottom-all-loaded="bottomAll ...

  3. vue上拉加载下拉加载

    npm i vue-scroller <scroller :on-refresh="refresh" :on-infinite="infinite" :n ...

  4. 微信小程序 - 上拉加载更多组件

    详情用例看demo,点击下载示例:loadmore

  5. vue 上拉加载更多

    var _this=this; var goods_id = _this.$route.query.id; var isscroll = true; _this.$nextTick(() => ...

  6. vue mpvue 上拉加载更多示例代码

    vue 上拉加载更多示例代码 可以比较简单的改为 mpvue , 去除滚动判断,直接放在 onReachBottom 周期即可. html <div id="app"> ...

  7. react-native 模仿原生 实现下拉刷新/上拉加载更多(RefreshListView)

    1.下拉刷新/上拉加载更多 组件(RefreshListView) src/components/RefreshListView/index.js /** * 下拉刷新/上拉加载更多 组件(Refre ...

  8. [RN] React Native 实现 FlatList上拉加载

     FlatList可以利用官方组件 RefreshControl实现下拉刷新功能,但官方没有提供相应的上拉加载的组件,因此在RN中实现上拉加载比下拉刷新要复杂一点. 不过我们仍可以通过FlatList ...

  9. react antd上拉加载与下拉刷新与虚拟列表使用

    创建项目 create-react-app antdReact 安装:antd-mobile.react-virtualized npm i antd-mobile -S npm i react-vi ...

随机推荐

  1. spark-sql集合的“条件过滤”,“合并”,“动态类型映射DataFrame”,“存储”

    List<String> basicList = new ArrayList<String>(); basicList.add("{\"name\" ...

  2. asp.net NPOI导出xlsx格式文件,打开文件报“Excel 已完成文件级验证和修复。此工作簿的某些部分可能已被修复或丢弃”

    NPOI导出xlsx格式文件,会出现如下情况: 点击“是”: 导出代码如下: /// <summary> /// 将datatable数据写入excel并下载 /// </summa ...

  3. MongoDB 查询 $关键词 方法目录

    MongoDB $关键字 关系比较符号 $lt $lte $gt $gte $ne MongoDB 查询$关键字 $in $or $all MongoDB limit 选取 skip跳过 sort排序 ...

  4. workman项目设置开机自启动

    https://blog.csdn.net/xxq929604980/article/details/78558317 http://man.linuxde.net/chkconfig 1.脚本编写 ...

  5. Delphi中有关窗口绘制

    Invalidate方法通知Windows应该重新绘制表单的整个表面.最重要的是Invalidate不会立即强制执行绘制操作. Windows只是存储请求,并且只会响应它当前程序完全执行后,并且只要系 ...

  6. angular中的MVC思想

    MVC是一种使用 MVC(Model View Controller 模型-视图-控制器)设计模式,该模型的理念也被许多框架所吸纳.在学习angular的过程中,我在网上查找关于angular MVC ...

  7. 第二篇——Struts2的Action搜索顺序

    Struts2的Action的搜索顺序: 地址:http://localhost:8080/path1/path2/student.action     1.判断package是否存在,例如:/pat ...

  8. solr简单搜索案例

    solr简单搜索案例 使用Solr实现电商网站中商品信息搜索功能,可以根据关键字搜索商品信息,根据商品分类.价格过滤搜索结果,也可以根据价格进行排序,实现分页. 架构分为: 1. solr服务器 2. ...

  9. PhpStorm 2017破解

    最新版PhpStorm 2017正式版改进了PHP 7支持,改进代码完成功能. PhpStorm 是最好的PHP开发工具,使用它进行PHP开发将会让你感觉到编程的乐趣. 快乐无极终于从oschina看 ...

  10. CSS 层级选择器

    CSS 层级选择器 注:使用空格分隔,塞选到最后一项应用. 标签选择器 下 标签选择器 父标签 --> 指定子标签添加css属性 <html> <head> <!- ...