<template>
<gracePage :customHeader="false">
<view slot="gBody" class="grace-body">
<view class="grace-margin-top grace-text-center">
<text class="grace-text">请上拉屏幕加载更多 ^_^</text>
</view>
<view class="grace-wrap grace-margin-top">
<view class="demo grace-bg-blue" v-for="(item, index) in demoDate" :key="index">{{item}}</view>
</view>
<graceLoading :loadingType="loadingType"></graceLoading>
</view>
</gracePage>
</template>
<script>
import gracePage from "../../graceUI/components/gracePage.vue";
import graceLoading from '../../graceUI/components/graceLoading.vue';
var demoDate = ["H", "C", 'O', 'D', 'E', 'R', 'D', 'E', 'M', 'O', 'T', 'E', 'S', 'T'];
var page = 1; // 模拟页码
export default {
data() {
return {
demoDate: demoDate,
loadingType : 3
}
},
onReachBottom : function(){
//避免多次触发
if (this.loadingType == 1 || this.loadingType == 2){return ;}
this.loadMoreFunc();
},
methods:{
//加载更多时执行的函数
loadMoreFunc: function (){
//假设 page > 3 代表加载了全部数据
// 实际开的过程以 api 接口返回数据为准
if (page > 3){
this.loadingType = 2;
return ;
}
//展示loading
this.loadingType = 1;
//追加数据(延迟1秒 模拟网络请求)
setTimeout(() => {
var newData = this.getArrRandomly(demoDate);
this.demoDate = this.demoDate.concat(newData);
//累加页码
page++;
this.loadingType = 0;
}, 1000);
},
getArrRandomly: function (arr) {
var len = arr.length;
for (var i = 0; i < len; i++) {
var randomIndex = Math.floor(Math.random() * (len - i));
var itemAtIndex = arr[randomIndex];
arr[randomIndex] = arr[i];
arr[i] = itemAtIndex;
}
return arr;
}
},
components:{
gracePage, graceLoading
}
}
</script>
<style>
.demo{border-radius:3px; height:200rpx; line-height:200rpx; text-align:center; width:320rpx; margin:15rpx; font-size:30rpx;}
</style>
<template>
<gracePage :customHeader="false">
<view slot="gBody" class="grace-body">
<view class="grace-margin-top">
<text class="grace-text grace-text-center">请上拉屏幕加载更多 ^_^</text>
</view>
<view class="grace-wrap grace-margin-top">
<text class="demo grace-bg-blue" v-for="(item, index) in demoDate" :key="index">{{item}}</text>
</view>
<graceLoading :loadingType="loadingType"></graceLoading>
</view>
</gracePage>
</template>
<script>
import gracePage from "../../graceUI/weexComponents/gracePage.nvue";
import graceLoading from '../../graceUI/weexComponents/graceLoading.nvue';
var demoDate = ["H", "C", 'O', 'D', 'E', 'R', 'D', 'E', 'M', 'O', 'T', 'E', 'S', 'T'];
var page = 1; // 模拟页码
export default {
data() {
return {
demoDate: demoDate,
loadingType : 3
}
},
onReachBottom : function(){
//避免多次触发
if (this.loadingType == 1 || this.loadingType == 2){return ;}
this.loadMoreFunc();
},
methods:{
//加载更多时执行的函数
loadMoreFunc: function (){
//假设 page > 3 代表加载了全部数据
// 实际开的过程以 api 接口返回数据为准
if (page > 3){
this.loadingType = 2;
return ;
}
//展示loading
this.loadingType = 1;
//追加数据(延迟1秒 模拟网络请求)
setTimeout(() => {
var newData = this.getArrRandomly(demoDate);
this.demoDate = this.demoDate.concat(newData);
//累加页码
page++;
this.loadingType = 0;
}, 1000);
},
getArrRandomly: function (arr) {
var len = arr.length;
for (var i = 0; i < len; i++) {
var randomIndex = Math.floor(Math.random() * (len - i));
var itemAtIndex = arr[randomIndex];
arr[randomIndex] = arr[i];
arr[i] = itemAtIndex;
}
return arr;
}
},
components:{
gracePage, graceLoading
}
}
</script>
<style>
.demo{border-radius:3px; height:200rpx; line-height:200rpx; text-align:center; width:320rpx; margin:15rpx; font-size:30rpx;}
</style>
.wxml
<gracePage customHeader="{{false}}">
<view slot="gBody" class="grace-body">
<view class="grace-margin-top grace-text-center">
<text class="grace-text">请上拉屏幕加载更多 ^_^</text>
</view>
<view class="grace-wrap grace-margin-top">
<view class="demo grace-bg-blue" wx:for="{{demoDate}}" wx:key="index">{{item}}</view>
</view>
<graceLoading loadingType="{{loadingType}}"></graceLoading>
</view>
</gracePage>.wxss
.demo{border-radius:3px; height:200rpx; line-height:200rpx; text-align:center; width:320rpx; margin:15rpx; font-size:30rpx;}.js
var demoDate = ["H", "C", 'O', 'D', 'E', 'R', 'D', 'E', 'M', 'O', 'T', 'E', 'S', 'T'];
var page = 1; // 模拟页码
Page({
data: {
demoDate: demoDate,
loadingType: 3
},
//下拉刷新事件
onReachBottom: function () {
//避免多次触发
if (this.data.loadingType == 1 || this.data.loadingType == 2) { return; }
this.loadMoreFunc();
},
//加载更多时执行的函数
loadMoreFunc: function () {
//假设 page > 3 代表加载了全部数据
// 实际开的过程以 api 接口返回数据为准
if (page > 3) {
this.setData({loadingType : 2});
return;
}
//展示loading
this.setData({ loadingType: 1 });
//追加数据(延迟1秒 模拟网络请求)
setTimeout(() => {
var newData = this.getArrRandomly(demoDate);
this.setData({ demoDate: this.data.demoDate.concat(newData)});
//累加页码
page++;
this.setData({ loadingType: 0 });
}, 1000);
},
getArrRandomly: function (arr) {
var len = arr.length;
for (var i = 0; i < len; i++) {
var randomIndex = Math.floor(Math.random() * (len - i));
var itemAtIndex = arr[randomIndex];
arr[randomIndex] = arr[i];
arr[i] = itemAtIndex;
}
return arr;
}
}).json
{
"usingComponents": {
"gracePage": "../../graceUI/components/gracePage",
"graceLoading": "../../graceUI/components/graceLoading"
}
}