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 ...
随机推荐
- react中进入某个详情页URL路劲参数Id获取问题
<Route path={`${match.url}/detail/:id`} component={AppManageAddDetail} /> const { match:{param ...
- poi导入excel表格数据到数据库的时候,对出生日期的校验
出生日期格式为8位数字的字符串 如:yyyyMMdd 规则:yyyy大于1900并小于当前时间,月.日 按日期规则校验 //解决读过来的字符串显示为科学计数法问题 BigDecimal bd = ne ...
- PTA 树的遍历
给定一棵二叉树的后序遍历和中序遍历,请你输出其层序遍历的序列.这里假设键值都是互不相等的正整数. 输入格式: 输入第一行给出一个正整数N(≤30),是二叉树中结点的个数.第二行给出其后序遍历序列.第三 ...
- JMeter上架标的(yyb-csg)
yyb-csg 1.登录时一直提示用户名不能为空,可是明明已经传值了呀 解决:添加cookie管理器 2.怎么获取到待受理的项目, 在python脚本的实现过程中发现,在平台受理一步中传的lid值就是 ...
- Java文件写入与读取实例求最大子数组
出现bug的点:输入数组无限大: 输入的整数,量大: 解决方案:向文件中输入随机数组,大小范围与量都可以控制. 源代码: import java.io.BufferedReader; import j ...
- vue 之iview
iView-admin2.0:https://admin.iviewui.com/ 组件:https://www.iviewui.com/docs/guide/install
- 与数论的厮守01:素数的测试——Miller Rabin
看一个数是否为质数,我们通常会用那个O(√N)的算法来做,那个算法叫试除法.然而当这个数非常大的时候,这个高增长率的时间复杂度就不够这个数跑了. 为了解决这个问题,我们先来看看费马小定理:若n为素数, ...
- flask重要点
django与flask的区别 django: 大而全的框架,包含了很多组件,例如:ORM.form.ModelForm.session... flask: 轻量级的可扩展强的框架.有丰富的第三方组件 ...
- vs2017添加引用出错:对COM组件的调用返回了错误HRESULT E_FAIL
1.以管理员身份打开 Developer Command Prompt for VS 2017(vs2017开发人员命令提示符) 2.定位到你的vs2017的安装目录 例:E:\Program Fil ...
- js实现复制内容到剪切板,兼容pc和手机端,支持Safari浏览器
Javascript原生有一些事件:copy.paste.cut, 这些事件可以作用的目标元素: 能获得焦点的元素 (如contentEditable内容能编辑或者可以选中的元素),或者是<bo ...