日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學(xué)無先后,達者為師

網(wǎng)站首頁 編程語言 正文

uni-app項目之商品列表的下拉刷新與上拉加載更多

作者:小渣亮 更新時間: 2022-04-23 編程語言

目錄

  • 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

欄目分類
最近更新