当前位置:网站首页>uni-app项目之 商品列表的下拉刷新 与 上拉加载更多
uni-app项目之 商品列表的下拉刷新 与 上拉加载更多
2022-04-22 09:25:00 【小渣亮】
目录
uni-app项目之 商品列表的下拉刷新 与 上拉加载更多
uni-app项目之 商品列表的 上拉加载更多
goods.vue
<template>
<view class="goods_wrap">
<view class="goods_list">
<view class="goods_list_item" v-for="item in shopList">
{
{
item.title}}
</view>
</view>
<view class="isOver" v-if="isOverFlag">
----我是有底线的----
</view>
</view>
</template>
<script>
export default {
data() {
return {
shopList:[],
pageIndex:1,
isOverFlag:false,
}
},
onLoad() {
this.getShopList();
},
// 触底触发
onReachBottom() {
console.log("触底触发", this.shopList.length);
// 先判断是否有下一页的数据
if ( this.shopList.length < this.pageIndex * 10) return this.isOverFlag = true;
this.pageIndex++
this.getShopList();
},
methods: {
// 获取商品列表
async getShopList(){
const res = await this.$myHttp({
url:"/shopList?pageIndex=" + this.pageIndex,
})
// 获取商品数据
this.shopList = [...this.shopList,...res.data];
},
}
}
</script>
<style lang="scss">
.goods_wrap{
height: 100%;
width: 100%;
background: pink;
.goods_list {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
padding: 0 15rpx;
.goods_list_item {
box-sizing: border-box;
margin-bottom: 15rpx;
background: #fff;
width: 355rpx;
height: 400rpx;
line-height: 400rpx;
text-align: center;
}
}
.isOver {
width: 100%;
text-align: center;
}
}
</style>
效果

uni-app项目之 商品列表的下拉刷新
goods.vue
<template>
<view class="goods_wrap">
<view class="goods_list">
<view class="goods_list_item" v-for="item in shopList">
{
{
item.title}}
</view>
</view>
<view class="isOver" v-if="isOverFlag">
----我是有底线的----
</view>
</view>
</template>
<script>
export default {
data() {
return {
shopList:[],
pageIndex:1,
isOverFlag:false,
}
},
onLoad() {
this.getShopList();
},
// 触底触发
onReachBottom() {
console.log("触底触发", this.shopList.length);
// 先判断是否有下一页的数据
if ( this.shopList.length < this.pageIndex * 10) return this.isOverFlag = true;
this.pageIndex++
this.getShopList();
},
// 下拉刷新了
onPullDownRefresh(){
console.log("下拉刷新了");
this.pageIndex = 1;
this.shopList = [];
this.isOverFlag = false;
setTimeout(()=> {
this.getShopList(()=>{
uni.stopPullDownRefresh(); // 关闭下拉刷新
});
}, 1000 )
},
methods: {
// 获取商品列表
async getShopList(callBack){
const res = await this.$myHttp({
url:"/shopList?pageIndex=" + this.pageIndex,
})
// 获取商品数据
this.shopList = [...this.shopList,...res.data];
callBack && callBack()
},
}
}
</script>
<style lang="scss">
.goods_wrap{
height: 100%;
width: 100%;
background: pink;
.goods_list {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
padding: 0 15rpx;
.goods_list_item {
box-sizing: border-box;
margin-bottom: 15rpx;
background: #fff;
width: 355rpx;
height: 400rpx;
line-height: 400rpx;
text-align: center;
}
}
.isOver {
width: 100%;
text-align: center;
}
}
</style>
pages.json
- “enablePullDownRefresh”:true//
{
"pages": [ //pages数组中第一项表示应用启动页,参考:https://uniapp.dcloud.io/collocation/pages
{
"path": "pages/index/index"
}
,{
"path" : "pages/cart/cart"
}
,{
"path" : "pages/member/member"
}
,{
"path" : "pages/news/news"
}
,{
"path" : "pages/goods/goods",
"style": {
"enablePullDownRefresh":true// 开启下拉刷新
}
}
,{
"path" : "pages/contact/contact"
}
,{
"path" : "pages/pics/pics"
}
,{
"path" : "pages/learn/learn"
}
],
"globalStyle": {
"navigationBarTextStyle": "white",
"navigationBarTitleText": "xzl-商场",
"navigationBarBackgroundColor": "#b50e03",
"backgroundColor": "#F8F8F8"
},
"tabBar":{
"selectedColor":"#b50e03",
"list":[
{
"text":"首页",
"pagePath":"pages/index/index",
"iconPath":"static/icon/home.png",
"selectedIconPath":"static/icon/home-active.png"
},
{
"text":"新闻",
"pagePath":"pages/news/news",
"iconPath":"static/icon/news.png",
"selectedIconPath":"static/icon/news-active.png"
},
{
"text":"购物车",
"pagePath":"pages/cart/cart",
"iconPath":"./static/icon/cart.png",
"selectedIconPath":"static/icon/cart-active.png"
},
{
"text":"会员",
"pagePath":"pages/member/member",
"iconPath":"static/icon/member.png",
"selectedIconPath":"static/icon/member-active.png"
}
]
}
}
效果
- 上拉

版权声明
本文为[小渣亮]所创,转载请带上原文链接,感谢
https://blog.csdn.net/weixin_43845137/article/details/124336024
边栏推荐
- 杰理之CPU性能测试【篇】
- numpy笔记(vstack,random.permutation,empty_like,empty,diff,random.choice,random.randint,isin)
- How to add mailbox email in MySQL data table
- 2022年熔化焊接与热切割操作证考试题模拟考试平台操作
- The bare metal machine developed by single chip microcomputer can also "multitask"?
- 好用的记笔记软件
- Easy to use screenshot software
- 基于麒麟SP10服务器版的Kubernetes集群安装
- 六个方法,可以让你在NFT交易中收益更多
- 浅析MOS管开关速度影响因素-KIA MOS管
猜你喜欢

Axure 如何在页面加载时,设置文本框的内容为当前日期

MySQL on duplicate key update / case when syntax

2022低压电工考试题及答案

2022起重机司机(限桥式起重机)考试题库及在线模拟考试

openlayer中,svg图片无width如何修改大小

Quantitative investment learning -- Introduction to orderflow

MOS管驱动电路及注意事项-KIA MOS管

Computer dust removal and mechanical hard disk installation records

编写一个简单的考试程序,在控制台完成出题、答题的交互。试题(Question)分为单选(SingleChoice)和多选( MultiChoice)两种。

Halo 开源项目学习(一):项目启动
随机推荐
安装Navicat 15 详解及相关问题详解
Unicorn Bio筹集320万美元资金 将用于培养肉的原型设备变成商业产品
浅析MOS管开关速度影响因素-KIA MOS管
Axure 如何在页面加载时,设置文本框的内容为当前日期
六个方法,可以让你在NFT交易中收益更多
Six methods can make you gain more in NFT trading
Palindrome linked list (copy linked list to array, speed pointer + reverse linked list)
杰理之AI Server【篇】
杰理之通常影响CPU性能测试结果的因素有:【篇】
Cmake uses the basic grammar of basic knowledge I
How to add mailbox email in MySQL data table
oracle18c rac安装grid执行脚本root.sh报错,PRCR-1013 : 无法启动资源 ora.ons
I/O知识点总结
好用的记笔记软件
运维数据该如何防泄露
微搭低代码零基础入门课(第二课)
npm yarn 启动报错【已解决】
Advanced view of MySQL
杰理之CPU性能测试【篇】
2022年危险化学品经营单位安全管理人员上岗证题库及在线模拟考试