網(wǎng)站首頁 編程語言 正文
目錄
- uni-app項目之 商品列表的下拉刷新 與 上拉加載更多
- uni-app項目之 商品列表的 上拉加載更多
- goods.vue
- 效果
- uni-app項目之 商品列表的下拉刷新
- goods.vue
- pages.json
- 效果
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();
},
// 觸底觸發(fā)
onReachBottom() {
console.log("觸底觸發(fā)", this.shopList.length);
// 先判斷是否有下一頁的數(shù)據(jù)
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,
})
// 獲取商品數(shù)據(jù)
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();
},
// 觸底觸發(fā)
onReachBottom() {
console.log("觸底觸發(fā)", this.shopList.length);
// 先判斷是否有下一頁的數(shù)據(jù)
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(); // 關(guān)閉下拉刷新
});
}, 1000 )
},
methods: {
// 獲取商品列表
async getShopList(callBack){
const res = await this.$myHttp({
url:"/shopList?pageIndex=" + this.pageIndex,
})
// 獲取商品數(shù)據(jù)
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數(shù)組中第一項表示應(yīng)用啟動頁,參考: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
相關(guān)推薦
- 2022-10-22 關(guān)于redis的延遲雙刪策略總結(jié)_Redis
- 2022-07-19 Python數(shù)據(jù)分析?Numpy?的使用方法_python
- 2022-08-28 強制緩存和協(xié)商緩存的區(qū)別是什么?對稱、非對稱加密的區(qū)別是什么?
- 2022-10-31 Android開發(fā)Compose框架使用開篇_Android
- 2022-06-08 Golang原生rpc(rpc服務(wù)端源碼解讀)_Golang
- 2022-06-14 jquery實現(xiàn)點擊按鈕顯示與隱藏效果_jquery
- 2022-09-04 Redis分布式鎖解決秒殺超賣問題_Redis
- 2022-09-26 Pytorch模型訓(xùn)練和模型驗證
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細win安裝深度學(xué)習(xí)環(huán)境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎(chǔ)操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權(quán)
- redisson分布式鎖中waittime的設(shè)
- maven:解決release錯誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務(wù)發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡單動態(tài)字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應(yīng)用詳解
- 聊聊消息隊列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支