一、实现效果
二、数据几口
【GET】https://www.escook.cn/categories
三、代码
1、WXML
<view class="container">
<view wx:for="{{itemIcon}}" class="item">
<image src="{{item.icon}}"></image>
<text>{{item.name}}</text>
</view>
</view>
2、WXSS
.container {
padding: 0;
display: flex;
flex-wrap: wrap;
flex-direction: row;
text-align: center;
}
.item{
width: 33.33%;
height: 250rpx;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
border-right: 2rpx solid #ccc;
border-bottom: 2rpx solid #ccc;
font-size: 24rpx;
box-sizing: border-box;
}
.container .item:nth-child(3n) {
border-right: none;
}
.container image {
width: 40rpx;
height: 40rpx;
}
3、js代码
Page({
data: {
itemIcon:[],
},
onLoad(options) {
wx.request({
url: 'https://www.escook.cn/categories',
method:'GET',
success:(res)=>{
this.setData({
itemIcon:res.data
})
}
})
},
})