vue 使用mint

解决了官网中下拉刷新存在的问题

1<template> 2 <div class="tmpl"> 3 <nav-bar title="商品列表"></nav-bar> 4 <div class="main-body" ref="wrapper" :style="{ height: (wrapperHeight-50) + 'px' }"> 5 <mt-loadmore :top-method="loadTop" :bottom-method="loadBottom" :bottom-all-loaded="allLoaded" ref="loadmore" :autoFill="isAutoFill"> 6 <ul class="mui-table-view mui-grid-view"> 7 <li v-for="(item,index) in datas" :key="index" class="mui-table-view-cell mui-media mui-col-xs-6"> 8 <a> 9 <img class="mui-media-object" v-lazy="item.img"> 10 <div class="mui-media-body" v-text="item.title"></div> 11 </a> 12 </li> 13 </ul> 14 </mt-loadmore> 15 </div> 16 </div> 17</template> 18 19<script> 20export default { 21 name: "goodslist", 22 data() { 23 return { 24 datas: [], 25 //可以进行上拉 26 allLoaded: false, 27 //是否自动触发上拉函数 28 isAutoFill: false, 29 wrapperHeight: 0, 30 courrentPage: 0 31 }; 32 }, 33 created() { 34 this.loadFrist(); 35 }, 36 mounted() { 37 // 父控件要加上高度,否则会出现上拉不动的情况 38 this.wrapperHeight = 39 document.documentElement.clientHeight - 40 this.$refs.wrapper.getBoundingClientRect().top; 41 }, 42 methods: { 43 // 下拉刷新 44 loadTop() { 45 this.loadFrist(); 46 }, 47 // 上拉加载 48 loadBottom() { 49 this.loadMore(); 50 }, 51 // 下来刷新加载 52 loadFrist() { 53 this.$axios 54 .get("goodslist1.json") 55 .then(response => { 56 this.courrentPage = 0; 57 this.allLoaded = false; // 可以进行上拉 58 this.datas = response.data.message; 59 this.$refs.loadmore.onTopLoaded(); 60 }) 61 .catch(error => { 62 console.log(error); 63 alert("网络错误,不能访问"); 64 }); 65 }, 66 // 加载更多 67 loadMore() { 68 this.$axios 69 .get("goodslist.json") 70 .then(response => { 71 // concat数组的追加 72 this.datas = this.datas.concat(response.data.message); 73 if (this.courrentPage > 2) { 74 this.allLoaded = true; // 若数据已全部获取完毕 75 } 76 this.courrentPage++; 77 this.$refs.loadmore.onBottomLoaded(); 78 }) 79 .catch(error => { 80 console.log(error); 81 alert("网络错误,不能访问"); 82 }); 83 } 84 } 85}; 86</script> 87 88<!-- Add "scoped" attribute to limit CSS to this component only --> 89<style scoped> 90.main-body { 91 /* 加上这个才会有当数据充满整个屏幕,可以进行上拉加载更多的操作 */ 92 overflow: scroll; 93} 94</style>
点赞
收藏

评论区

加载中...

相关推荐

MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1

文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s

Oracle 分组与拼接字符串同时使用

SELECTT.,ROWNUMIDFROM(SELECTT.EMPLID,T.NAME,T.BU,T.REALDEPART,T.FORMATDATE,SUM(T.S0)S0,MAX(UPDATETIME)CREATETIME,LISTAGG(TOCHAR(

MySQL部分从库上面因为大量的临时表tmp_table造成慢查询

背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_

手写Java HashMap源码

HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程22

2020年前端实用代码段,为你的工作保驾护航

有空的时候,自己总结了几个代码段,在开发中也经常使用,谢谢。1、使用解构获取json数据let jsonData  id: 1,status: "OK",data: 'a', 'b';let  id, status, data: number   jsonData;console.log(id, status, number )

AndroidStudio封装SDK的那些事

<divclass"markdown\_views"<!flowchart箭头图标勿删<svgxmlns"http://www.w3.org/2000/svg"style"display:none;"<pathstrokelinecap"round"d"M5,00,2.55,5z"id"raphael