vue 上拉加载自定义组件,超好用哦
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 上拉加载自定义组件,超好用哦的更多相关文章
- react-native 自定义 下拉刷新 / 上拉加载更多 组件
1.封装 Scroller 组件 /** * 下拉刷新/上拉加载更多 组件(Scroller) */ import React, {Component} from 'react'; import { ...
- vux, vue上拉加载更多
<template> <" :bottom-method="loadBottom" :bottom-all-loaded="bottomAll ...
- vue上拉加载下拉加载
npm i vue-scroller <scroller :on-refresh="refresh" :on-infinite="infinite" :n ...
- 微信小程序 - 上拉加载更多组件
详情用例看demo,点击下载示例:loadmore
- vue 上拉加载更多
var _this=this; var goods_id = _this.$route.query.id; var isscroll = true; _this.$nextTick(() => ...
- vue mpvue 上拉加载更多示例代码
vue 上拉加载更多示例代码 可以比较简单的改为 mpvue , 去除滚动判断,直接放在 onReachBottom 周期即可. html <div id="app"> ...
- react-native 模仿原生 实现下拉刷新/上拉加载更多(RefreshListView)
1.下拉刷新/上拉加载更多 组件(RefreshListView) src/components/RefreshListView/index.js /** * 下拉刷新/上拉加载更多 组件(Refre ...
- [RN] React Native 实现 FlatList上拉加载
FlatList可以利用官方组件 RefreshControl实现下拉刷新功能,但官方没有提供相应的上拉加载的组件,因此在RN中实现上拉加载比下拉刷新要复杂一点. 不过我们仍可以通过FlatList ...
- react antd上拉加载与下拉刷新与虚拟列表使用
创建项目 create-react-app antdReact 安装:antd-mobile.react-virtualized npm i antd-mobile -S npm i react-vi ...
随机推荐
- elasticsearch head添加索引并设置mapping
直接用put方法创造一个东西出来 然后post请求,设置mapping
- 【Python全栈-后端开发】Django进阶之Model操作复习
Django进阶之Model操作复习 一.字段 AutoField(Field) - int自增列,必须填入参数 primary_key=True BigAutoField(AutoField) - ...
- iOS 如果页面 A 跳转到 页面 B,A 的 viewDidDisappear 方法和 B 的 viewDidAppear 方法哪个先调用?
如果页面 A 跳转到 页面 B,A 的 viewDidDisappear 方法和 B 的 viewDidAppear 方法哪个先调用? 1. - (void)pushViewController:(U ...
- 判断是手机请求还是pc请求
网址 http://detectmobilebrowsers.com/ string u = Request.ServerVariables["HTTP_USER_AGENT"]; ...
- 020-并发编程-java.util.concurrent之-jdk6/7/8中ConcurrentHashMap、HashMap分析
一.概述 哈希表(hash table)也叫散列表,是一种非常重要的数据结构,应用场景及其丰富,许多缓存技术(比如memcached)的核心其实就是在内存中维护一张大的哈希表. 是根据关键码值(Key ...
- linux-grep-tail-find
如果在只是想匹配模式的上下几行,grep可以实现. $grep -5 'parttern' inputfile //打印匹配行的前后5行 $grep -C 5 'parttern' inputfile ...
- Python3使用AES加密的库函数PyCrypto、PyCryptodome
我们在网上查看Python爬虫教程的时候,细心的朋友会发现:很多网站为了降低服务器的请求压力都做了各式各样的反爬策略,浏览器通过http post请求服务器端数据时,传输的data字段很多都是经过加密 ...
- Python Pyinstaller打包含pandas库的py文件遇到的坑
今天的主角依然是pyinstaller打包工具,为了让pyinstaller打包后exe文件不至过大,我们的py脚本文件引用库时尽可能只引用需要的部分,不要引用整个库,多使用“from *** imp ...
- 异常分类VS垃圾分类
异常分类VS垃圾分类 容易快速判断出是什么业务异常,容易对不同的异常进行不同的处理,容易很快找到对应的解决方法
- postman接口自动化,环境变量的用法详解(附postman常用的方法)
在实现接口自动测试的时候,会经常遇到接口参数依赖的问题,例如调取登录接口的时候,需要先获取登录的key值,而每次请求返回的key值又是不一样的,那么这种情况下,要实现接口的自动化,就要用到postma ...