微信小程序: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;
}

样式总览

相关推荐
2501_915918412 小时前
iOS 应用上架全流程实践,从开发内测到正式发布的多工具组合方案
android·ios·小程序·https·uni-app·iphone·webview
上海云盾第一敬业销售7 小时前
小程序被爬虫攻击,使用waf能防护吗?
爬虫·小程序
suncentwl8 小时前
做一个答题pk小程序多少钱?
小程序·答题小程序·知识竞赛·答题pk软件
说私域8 小时前
基于开源链动2+1模式AI智能名片S2B2C商城小程序的流量转化策略研究
人工智能·小程序
咸虾米_9 小时前
微信小程序通过uni.chooseLocation打开地图选择位置,相关设置及可能出现的问题
微信小程序·小程序·uniapp开发·小程序地图api
未来之窗软件服务10 小时前
蔬菜批发小程序:生产商的数字化转型利器——仙盟创梦IDE
小程序·自动化·仙盟创梦ide·东方仙盟·蔬菜批发·批发系统
数据皮皮侠14 小时前
最新上市公司业绩说明会文本数据(2017.02-2025.08)
大数据·数据库·人工智能·笔记·物联网·小程序·区块链
不如摸鱼去1 天前
Trae 辅助下的 uni-app 跨端小程序工程化开发实践分享
微信小程序·小程序·uni-app·aigc·ai编程
七夜zippoe1 天前
如何使用 AI 大语言模型解决生活中的实际小事情?
人工智能·语言模型·生活
意会1 天前
微信闪照小程序实现
前端·css·微信小程序