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. angular--获取时间方法services

    写了一些公用方法获取自然周.传入开始和结束日期,获取中间全部日期等方法 .service('DateServices', [function () { // 获取某年自然周的方法 (如果是当年,只返回 ...

  2. 代码中特殊的注释技术——TODO、FIXME和XXX的用处(转)

    1.声明 本篇转自博客:http://blog.csdn.net/reille/ 2.转载内容 2.1.前言 今天在阅读 Qt Creator 的源代码时,发现一些注释中有 FIXME 英文单词,用英 ...

  3. 谈谈那些年我们装B的并发编程

    谈谈那些年我们装B的并发编程 每个人对并发编程的理解会有差异,但是终极目标始终是追求尽可能高的处理性能.那么如何尽可能的提升处理性能呢? 我们可以从单核,多核,并发,并行的基础出发.首先,介绍下基础知 ...

  4. 解决xp突然出现开机登录界面的问题

    对系统进行网络相关的设置后,有时会让系统开启时突然冒出登录窗口,即使我们没有对自己的系统设置开机密码,也会冒出这个,需要回车一下才会进入系统:关机时,xp特有的“关机”,“待机”,“重新启动”按钮会变 ...

  5. cocos2dx 实现文字的一键复制功能(IOS、Android)

    1.IOS篇(用OC和C++混编) 头文件声明: public static void copy(std::string str); 实现如下: void copy(std::string str) ...

  6. usermod - linux修改用户帐户信息

    usermod - 修改用户帐户信息 modify a user account usermod [options] user_name usermod 命令修改系统帐户文件来反映通过命令行指定的变化 ...

  7. Python之猴子补丁

    1.在运行时,对属性,方法,函数等进行动态替换 2.其目的往往是为了通过替换,修改来增强,扩展原有代码的能力 #test2.py class Person: def get_score(self): ...

  8. IRC 打字交流

    kali 里面用 apt-get install weechat 安装完成后,输入 weechat 命令就能启动客户端了 要想使用 IRC,就需要先连接一个 irc 服务器,选择了大名鼎鼎的 chat ...

  9. Class_fifth

    1,统计文件夹的文件总数 代码: package Class_fifth; import java.io.File; public class Statistics { public static v ...

  10. C#对象序列化成XML,以及自定义标签名

    C#对象序列化操作: public class XMLHelper { /// <summary> /// 对象序列化成 XML String /// </summary> p ...