微信小程序:11.本地生活小程序制作


开发工具:

  • 微信开发者工具
  • apifox进行创先Mock

项目初始化

  1. 新建小程序项目
  2. 输入ID
  3. 选择不使用云开发,js传统模版
  4. 在project.private.config中setting配置项中配置checkinalidKey:false

梳理项目结构

因为该项目有三个tabbar所以我们要创建三个页面

  1. 首页
  2. 消息
  3. 联系我们

设置文本以及导航栏

配置tabBar效果

 "tabBar": {
    "list": [{
      "pagePath": "pages/home/home",
      "text": "首页",
      "iconPath": "image/tabBar/home.png",
      "selectedIconPath": "/image/tabBar/home1.png"
    },{
      "pagePath": "pages/message/message",
      "text": "消息",
      "iconPath": "image/tabBar/message.png",
      "selectedIconPath": "image/tabBar/message1.png"
    },{
      "pagePath": "pages/contaceus/contaceus",
      "text": "联系我们",
      "iconPath": "image/tabBar/content.png",
      "selectedIconPath": "image/tabBar/content1.png"
    }]
  },

使用阿里矢量图标库下载图片放入,image进行使用,效果如下

设置banner轮播图

使用apifox进行后台模拟Mock数据,使用Mock语法进行数据生成

在js中请求api

// 获取轮播图函数
  getSwiperList(){
    wx.request({
    url: 'https://mock.apifox.com/m1/4376673-0-default/api/swiperList',
    method:'GET',
    success:(res)=>{
        console.log(res);
        this.setData({
          swiperList:res.data.image
        })
    }
  })
  },

定义swiperList进行数据存放,然后在wxml中进行数据渲染

<!-- 轮播图 -->
<swiper indicator-dots>
  <swiper-item wx:for="{{swiperList}}" wx:key="id">
    <image src="{{item.path}}" mode=""/>
  </swiper-item>
</swiper>

设置九宫格

在js中请求数据

// 获取九宫格函数
  getGrideList(){
    wx.request({
      url: 'https://mock.apifox.com/m1/4376673-4020798-default/api/gridelist',
      method:'GET',
      success:(res)=>{
        console.log(res.data.gridelist);
        this.setData({
          gridList:res.data.gridelist
        })
      }
    })
  },

在wxml中进行数据渲染

<!-- 九宫格区域 -->
<view class="gride-list">
  <view class="grid-item" wx:for="{{gridList}}" wx:key="id">
    <image src="{{item.icon}}" mode=""/>
    <text>{{item.name}}</text>
  </view>
</view>

wxss样式

/* 九宫格样式设置 */
.gride-list{
  display: flex;
  flex-wrap: wrap;
  border-left: 1rpx solid #efefef;
  border-top: 1px solid #efefef;
}
.grid-item{
  width: 33%;
  height: 200rpx;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border-right: 1rpx solid #efefef;
  border-bottom: 1px solid #efefef;
  box-sizing: border-box;
}

.grid-item image {
  width: 60rpx;
  height: 60rpx;
}

.grid-item text{
  margin-top: 10rpx;
  font-size: 24rpx;
}

底部图片的设置

wxml设置

<!-- 图片区域 -->
<view class="img-box">
  <image src="../../image/link01.png" mode="widthFix heightFix"/>
  <image src="../../image/link02.png" mode="widthFix heightFix"/>
</view>

wxss设置

/* 底部样式 */
.img-box{
  display: flex;
  padding: 20rpx 10rpx;
  justify-content: space-around;
}
.img-box image{
  width: 340rpx;
  height: 300rpx;
}

样式总览

相关推荐
萧寂1732 小时前
微信小程序自定义轮播图指示点样式
微信小程序·小程序
SuperherRo10 小时前
自动化反编译微信小程序工具-e0e1-wx
微信小程序·自动化·hook·反编译
R_yy10 小时前
微信小程序开发——视频播放实现(本地视频或者云端视频均可)
前端·微信小程序·小程序
京河小蚁13 小时前
解决Moodo调节心情模块-大声喊出来无法测量出音频分贝
微信小程序·音视频·ai编程·cursor
gange57414 小时前
AI将会取代生活的方方面面吗?
人工智能·ai·ai作画·生活·ai编程·ai写作·百度云
低代码布道师15 小时前
加油站小程序实战教程03站点管理
低代码·小程序
蒜香拿铁15 小时前
小程序参数获取方式
前端·微信小程序
V+zmm1013418 小时前
智慧物流小程序(论文源码调试讲解)
java·数据库·微信小程序·小程序·毕业设计
霍格沃兹测试开发学社测试人社区18 小时前
性能测试丨微信小程序性能优化指南
性能优化·微信小程序·小程序