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": [
{
"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"
}
]
}
}
效果
- 上拉
|