Local life of WeChat applet development practice
Basic preparation knowledge
- Download the applet development tool and create a simple applet
- Use of basic applet components, API understanding
- js, css, html syntax understanding
2. Steps to realize the effect by level
Effect:
step:
- 1.配置app.json中导航栏、tabBar效果
- 2.配置导航栏
- 3.实现轮播图
- 4.实现九宫格
- 5.实现图片布局
add three pages
- Delete index in app.json
- Add three pages to app.json
- Modify the navigation bar
"pages": [
"pages/home/home",
"pages/message/message",
"pages/contact/contact"
],
"window": {
"backgroundTextStyle": "dark",
"navigationBarBackgroundColor": "#27BB9A",
"navigationBarTitleText": "本地生活",
"navigationBarTextStyle": "white",
"enablePullDownRefresh": true
},
Configure the tabBar effect
Add tabBar in app.json
Put the icons into the images folder
"tabBar": {
"list": [{
"pagePath": "pages/home/home",
"text": "首页",
"iconPath": "./images/home.png",
"selectedIconPath": "./images/home-active.png"
},{
"pagePath": "pages/message/message",
"text": "消息",
"iconPath": "./images/message.png",
"selectedIconPath": "./images/message-active.png"
},{
"pagePath": "pages/contact/contact",
"text": "联系我们",
"iconPath": "./images/contact.png",
"selectedIconPath": "./images/contact-active.png"
}]
}
Realization of Carousel
pages/home/home.xml builds a picture frame based on components
<!--轮播图区域-->
<!--indicator-dots 属性:显示面板指示点-->
<swiper indicator-dots circular>
<!--第一页-->
<swiper-item wx:for="{
{swiperList}}" wx:key="id">
<image src="{
{item.image}}"></image>
</swiper-item>
</swiper>
pages/home/home.wxss design carousel style
/* pages/home/home.wxss */
swiper {
height: 350rpx;
}
swiper image {
width: 100%;
height: 100%;
}
pages/home/home.js Get carousel image through request
Steps: 1. Add an array to receive the carousel in data: swiperList: [],
2. Add the acquisition function getSwiperList()
3. Register a function in onLoad: function (options) so that one of them will start when it enters the page: this.getSwiperList()
data: {
//存放轮播图的数据列表
swiperList: [],
},
onLoad: function (options) {
this.getSwiperList()
this.getGridList()
},
//获取轮播图数据的方法
getSwiperList() {
wx.request({
url: 'https://www.escook.cn/slides',
method:'GET',
success:(res) => {
this.setData({
swiperList:res.data
})
}
})
},
Realization of Jiugongge icon
pages/home/home.xml builds a picture frame based on components
<!--九宫格区域-->
<view class="grid-list">
<view class="grid-item" wx:for="{
{gridList}}" wx:key="id">
<image src="{
{item.icon}}"></image>
<text>{
{item.name}}</text>
</view>
</view>
pages/home/home.wxss Difficulties in designing Jiugongge style
/*外围大box*/
.grid-list{
display:flex;
flex:wrap /*多行且换行显示*/
border-left: 1rpx solid #efefef;
border-top: 1rpx solid #efefef;
}
/*每个图文*/
.grid-item{
display:flex
flex-direction:column;/*文字和图片按照列的方向排放*/
align-item: center;/*纵向居中*/
justify-content: center;/*横向居中居中*/
border-right: 1rpx solid #efefef;/*边框理解*/
border-bottom: 1rpx solid #efefef;
box-sizing: border-box;;/*默认是content-box百度自行理解*/
}
/*设置图片和文字的大小*/
.grid-item image {
width: 60rpx;
height: 60rpx;
}
.grid-item text {
font-size: 24rpx;
margin-top: 10rpx;
}
The acquisition of the pictures set in pages/home/home.js is the same as the carousel picture above
data: {
//存放轮播图的数据列表
swiperList: [],
//存放九宫格数据列表
gridList: []
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
this.getSwiperList()
this.getGridList()
},
//获取轮播图数据的方法
getSwiperList() {
wx.request({
url: 'https://www.escook.cn/slides',
method:'GET',
success:(res) => {
this.setData({
swiperList:res.data
})
}
})
},
// 获取九宫格数据的方法
getGridList() {
wx.request({
url: 'https://www.escook.cn/categories',
method: 'GET',
success: (res) => {
this.setData({
gridList: res.data
})
}
})
},
End picture setting (simple)
pages/home/home.xml builds a picture frame based on components
<!--图片区域-->
<view class="img-box">
<image src="../../images/link-01.png"></image>
<image src="../../images/link-02.png"></image>
</view>
pages/home/home.wxss design picture style
.img-box{
display:flex;
justify-content:space-around;
padding: 20rpx 10rpx;/* 上边下边 | 左边右边 */
}
.img-box image {
width: 45%;
}