## GIF
### 如果图片显示不出来,访问掘金:https://juejin.im/post/5ee1dc72e51d4574d17ea367
![](https://user-gold-cdn.xitu.io/2020/6/11/172a24bc07e492cc?w=373&h=664&f=gif&s=777740)
## list-mixin.js
```
/**
* uni-app上拉加载和下拉刷新混合
* @author maybe
*/
export default {
data() {
return {
loading: false, // 是否加载数据
finished: false, // 是否加载完成
list: [], // 数据列表
page: 0, // 由于分页一般页面要+1,所以为了方便分页查询,这里初始设置页码为0
size: 10, // 每页显示的条数
total: 0, // 数据总条数
search: {}, // 搜索对象
tempSearch: {} // 提供给混合初始化搜索对象
};
},
async onLoad() {
// 拷贝搜索初始化对象属性和数据
this.tempSearch = _deepClone(this.search);
console.log(this.tempSearch)
// 查询列表
await this._getListFactory();
},
// 下拉刷新
async onPullDownRefresh() {
console.log('下拉刷新');
this._initPageData();
this._resetSearch();
await this._getListFactory();
uni.stopPullDownRefresh();
},
// 上拉加载
async onReachBottom() {
console.log('上拉加载');
this._getListFactory();
},
// 所有混合的方法均已'_'开头
methods: {
async _searchData() {
this._initPageData();
await this._getListFactory();
},
// 重置搜索
_resetSearch() {
this.search = _deepClone(this.tempSearch)
// console.log('重置搜索完成', this.search)
},
// 初始化页面的数据
_initPageData(size) {
this.finished = false;
this.page = 0;
this.list = [];
this.size = size || 10;
this.total = 0;
},
async _getListFactory() {
// 如果已经全部加载完成直接终止执行
if (this.finished) return;
this.loading = true;
this.page++;
await this._getList();
this.loading = false;
// 判断是否全部加载完成
if (this.list.length == this.total) {
this.finished = true;
}
},
// 数据请求方法需要在页面内重写
async _getList() {}
}
}
// 深拷贝
const _deepClone = (source) => {
let target;
if (typeof source === 'object') {
target = Array.isArray(source) ? [] : {}
for (let key in source) {
if (source.hasOwnProperty(key)) {
if (typeof source[key] !== 'object') {
target[key] = source[key]
} else {
target[key] = _deepClone(source[key])
}
}
}
} else {
target = source
}
return target
};
```
## 示例
```
<template>
<view class="view">
<view class="notice">本Demo演示下拉刷新和上拉加载</view>
<view class="cu-bar search bg-white">
<view class="search-form round">
<text class="cuIcon-search"></text>
<input :adjust-position="false" v-model="search.text" type="text" placeholder="搜索图片、文章、视频" confirm-type="search"></input>
</view>
<view class="action">
<button class="cu-btn bg-green shadow-blur round" @tap="searchSubmit">搜索</button>
</view>
</view>
<view class="news-li" v-for="news in list" :key="news.id">
<view>{{ news.title }}</view>
<view class="new-content">
<text>{{ news.content }}</text>
</view>
<view class="new-content">
<text>{{ news.search }}</text>
</view>
</view>
<m-loading :loading="loading" :finished="finished"></m-loading>
</view>
</template>
<script>
/**
* 本页面提供演示
*/
import mLoading from '@/components/m-loading.vue';
import listMixin from '@/common/mixins/list-mixin.js';
export default {
mixins: [listMixin],
components: { mLoading },
data() {
return {
list: [], //列表必须为key list的数组
search:{ //搜索对象必须为key search的对象
text:'',
arr:[1,2,3]
}
};
},
methods: {
// 搜索
searchSubmit(){
// 调用混合搜索
this._searchData();
},
// 模拟后端分页
getData(requestParams) {
let self = this;
return new Promise((res, rej) => {
let params = requestParams;
if (!params) {
params = {
page: 1,
size: 10,
search:{
}
};
}
console.log(params)
setTimeout(() => {
let arr = [];
for (let i = (params.page - 1) * params.size; i < params.page * params.size; i++) {
arr.push({
id: i,
title: '【新增' + i + '】 标题',
content: '搜索对象为'+JSON.stringify(params.search),
});
}
res({
code: 200,
data: {
page: params.page,
size: params.size,
list: arr,
total: 20 // 设置20就加载完成
}
});
}, 500);
});
},
// 数据请求(没错就是这么少的代码)
async _getList() {
// 根据实际情况修改自己修改key
let result = await this.getData({
page:this.page, // 传入页码
size:this.size, // 传入每页条数
search:this.search // 传入搜索的对象
});
let self = this;
this.total = result.data.total;
result.data.list.map(item => {
self.list.push(item);
});
}
}
};
</script>
<style>
/*说明*/
.notice {
font-size: 30upx;
padding: 40upx 0;
border-bottom: 1upx solid #eee;
text-align: center;
}
/*展示上拉加载的数据列表*/
.news-li {
font-size: 32upx;
padding: 32upx;
border-bottom: 1upx solid #eee;
color: $uni;
}
.news-li .new-content {
font-size: 28upx;
margin-top: 10upx;
margin-left: 20upx;
color: #666;
}
</style>
```
没有合适的资源?快使用搜索试试~ 我知道了~
管理系统系列--连锁门店管理系统-门店手机版小程序进销存系统uniapp框架,门店库存管理系统.zip
共171个文件
vue:82个
png:59个
css:8个
需积分: 5 0 下载量 111 浏览量
2024-02-26
01:29:00
上传
评论
收藏 881KB ZIP 举报
温馨提示
管理系统系列--连锁门店管理系统-门店手机版小程序进销存系统uniapp框架,门店库存管理系统
资源推荐
资源详情
资源评论
收起资源包目录
管理系统系列--连锁门店管理系统-门店手机版小程序进销存系统uniapp框架,门店库存管理系统.zip (171个子文件)
icon.css 70KB
icon.css 70KB
main.css 63KB
iconfont.css 21KB
main.css 17KB
main.css 9KB
animation.css 3KB
w-picker.css 381B
.DS_Store 14KB
.DS_Store 8KB
.DS_Store 6KB
.DS_Store 6KB
.DS_Store 6KB
.DS_Store 6KB
loading.gif 82KB
.gitignore 22B
none.jpg 19KB
wxcharts-min.js 30KB
request.js 3KB
utils.js 2KB
icons.js 2KB
list-mixin.js 2KB
tabMask.js 2KB
host.js 230B
main.js 161B
pages.json 9KB
manifest.json 3KB
readme.md 5KB
README.md 2KB
title8.png 111KB
logo.png 41KB
release.png 26KB
confirm-word1.png 25KB
zhichu.png 25KB
baobiao.png 21KB
liushui.png 21KB
video.png 20KB
qa.png 18KB
meactive.png 16KB
convenient.png 16KB
homeactive.png 16KB
me.png 16KB
newsactive.png 16KB
home.png 16KB
news.png 15KB
none.png 12KB
pandian.png 10KB
wave.png 8KB
POS商户流水.png 7KB
feiyong.png 6KB
zhongduan.png 5KB
orderdown_20190411.png 5KB
diaobo.png 5KB
tab-home-current.png 5KB
close.png 4KB
xiaoshou.png 4KB
tab-home.png 4KB
scan_20190411.png 4KB
then.png 3KB
contact.png 3KB
tab-my.png 3KB
tab-cart-current.png 3KB
tab-cart.png 3KB
ruku.png 3KB
order-current.png 2KB
order.png 2KB
tab-my-current.png 2KB
guanzhu.png 2KB
guanzhuactive.png 2KB
play.png 2KB
icon_user.png 2KB
icon_message.png 2KB
icon_user_curr.png 1KB
close.png 1KB
cart.png 1KB
cart2.png 1KB
icon_home.png 1KB
add1.png 1KB
add.png 1KB
addactive.png 1KB
icon_message_curr.png 1KB
add_img.png 977B
icon_home_curr.png 953B
close.png 884B
tab-cate.png 866B
tab-cate-current.png 860B
jt.png 414B
more.png 235B
uni.scss 2KB
uni-icons.vue 80KB
chooseGoods.vue 52KB
edit.vue 47KB
add.vue 38KB
coupon.vue 32KB
amount.vue 29KB
times.vue 29KB
repertory.vue 29KB
date-picker.vue 25KB
customer.vue 23KB
marketing.vue 23KB
共 171 条
- 1
- 2
资源评论
Kwan的解忧杂货铺
- 粉丝: 1w+
- 资源: 3671
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功