<template> <div class="wrapper" ref="wrapper"> <div class="content" > <div class="refresh" :class="{ativeRefresh:refresh}">刷新</div> <div class="ct-row" v-for="(item,index) in formData.list" :key="index"> <div class="ct-row-list">{{item.id}}</div> <div class="ct-row-list">{{item.user}}</div> <div class="ct-row-list">{{item.des}}</div> </div> <div>加载</div> </div> </div> </template>
<script> import Bscroll from "better-scroll"; import axios from "axios"; import { clearTimeout, setTimeout } from ‘timers‘; export default { name: "wrapper", data() { return { formData: {}, refresh:false }; }, methods: { getFormDatas() { return axios.get("api/test/formData", { params: { id: 123456 } }) } }, created() { this.getFormDatas().then(res => { console.log(res.data); this.formData = res.data; this.formData.list.length=10; }); }, mounted() { let count=1; this.scroll = new Bscroll(this.$refs.wrapper, { mouseWheel: true, click: true, tap: true, pullDownRefresh: { threshold: 60,//下拉60px刷新 stop: 20//上弹到20px处,等待刷新完成 }, pullUpLoad:{ threshold: -20 //往下拉20px处时重新加载 } }); //下拉刷新 this.scroll.on("pullingDown", () => { this.refresh=true; this.getFormDatas().then(res => { const _this=this; // const timer=clearTimeout() setTimeout(()=>{ _this.refresh=false; _this.formData = res.data; _this.scroll.finishPullDown() },500) }); }); //上拉加载 this.scroll.on(‘pullingUp‘, () => { const _this=this; this.getFormDatas().then(res => { // const timer=clearTimeout() setTimeout(()=>{ _this.formData = res.data; _this.formData.length=20; _this.scroll.finishPullDown() },500) }); }) }, destroyed(){ this.scroll=null; } }; </script> <style scoped> /* wrapper要设置绝对定位 */ .wrapper { overflow: hidden; position: absolute; top: 0.9rem; left: 0; right: 0; bottom: 0; } .content { padding: 0 0.2rem 0 0.2rem; } .ct-row::after{ content: ""; height: 2px; width: 100%; background: #eee; display: block; } .ct-row-list{ height: .4rem; line-height: .4rem; } .refresh{ display: none; } .ativeRefresh{ display: block; } </style>
相关文章
- Android打造(ListView、GridView等)通用的下拉刷新、上拉自动加载的组件
- 移动端touch实现下拉刷新
- mui单页面 实现下拉刷新和上拉加载更多
- mui框架实现分页功能(上拉加载,下拉刷新)以及点击事件的实现
- 『uni-app』实现上拉加载,下拉刷新
- mpvue中小程序的scroll-view组件和全局配置的上拉加载,下拉刷新的区别
- iOS 上拉刷新和下拉加在更多(第三方框架EGOTableViewPullRefresh)
- 微信小程序scroll-view下拉刷新与上拉加载更多
- 微信小程序使用scroll-view,实现分页加载和下拉刷新
- Android实战简易教程-第二十五枪(基于Baas的数据表查询下拉刷新和上拉载入实现!)