微信小程序美食列表

 

index.js

// index.js
Page({
	data:{
		shopList:[],
	},
	listData:{
		page:1,
		pageSize:10,
		total:0
	},
	isLoading : false,

	getShopList:function(callback){
		this.isLoading = true
		wx.showLoading({
			title: '数据加载中...',
		})
		wx.request({
			url: 'http://127.0.0.1:3000/data',
			method:'GET',
			data:{
				page:this.listData.page,
				pageSize:this.listData.pageSize
			},
			success:res=>{
				console.log(res)
				this.setData({
					shopList:[...this.data.shopList, ...res.data],
				})
				this.listData.total = res.header['X-Total_Count'] - 0
			},
			complete:()=>{
				wx.hideLoading()
				this.isLoading = false
				callback && callback()
			}
		})
	},
	onLoad:function(){ 
		this.getShopList()
	},
	onReachBottom:function(){
		if(this.listData.page * this.listData.pageSize >=this.listData.total){
			return wx.showToast({
				title:'数据加载完毕',
				icon:'none',
			})
		}
		if(this.isLoading) {
			return
		}
		++this.listData.page
		this.getShopList()
	},
	onPullDownRefresh:function(){
		this.setData({
			shopList:[]
		})
		this.listData.page = 1
		this.listData.total = 0
		this.getShopList(() =>{
			wx.stopPullDownRefresh()
		})
	}
})

index.json

{
  "usingComponents": {
		"navigation-bar": "/components/navigation-bar/navigation-bar"
	},
	"onReachBottomDistance": 200,
	"enablePullDownRefresh":true,
	"backgroundColor": "#efefef",
	"backgroundTextStyle":"dark",
	"onPullDownRefresh":"true"

}

index.wxml


<wxs src="../../utils/tools.wxs" module="tools"></wxs>
<view class="shop-item" wx:for="{{shopList}}" wx:key="id">
  <view class="thumb">
	  <image src="{{item.image}}" />
	</view>
	<view class="info">
	  <text class="shop-title">{{item.name}}</text>
		<text>电话:{{tools.splitPhone(item.phone)}}</text>
		<text>地址:{{item.address}}</text>
		<text>营业时间:{{item.businessHours}}</text>
	</view>
</view>

index.wxss

/**index.wxss**/
.shop-item {
	display: flex;
	padding: 15rpx;
	border: 1rpx solid #efefef;
	border-radius: 8rpx;
	margin: 15rpx;
	box-shadow: 1rpx 1rpx 15rpx #ddd;
	}
	
.thumb image {
	width: 250rpx;
	height: 250rpx;
	display: block;
	margin-right: 15rpx;
}
	
.info {
	display: flex;
	flex-direction: column;
	justify-content: space-around;
	font-size: 24rpx;
}
	
.shop-title {
	font-weight: bold;
 }


  • 4
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值