微信小程序开发实战(一)开发指南

1. 目录结构

小程序包含一个描述整体程序的 app 和多个描述各自页面的 page。

文件必须作用
app.js小程序逻辑
app.json小程序公共配置
app.wxss小程序公共样式表

一个小程序页面由四个文件组成,分别是:

文件类型必须作用
js页面逻辑
wxml页面结构
json页面配置
wxss页面样式表

2. app.json 文件介绍

小程序根目录下的 app.json 文件用来对微信小程序进行全局配置,决定页面文件的路径、窗口表现、设置网络超时时间、设置多 tab 等。

2.1.自动创建page页面文件

在这里插入图片描述

2.2 菜单栏

在这里插入图片描述

"tabBar": {
  "list": [
     {
        "pagePath": "pages/index/index",
        "text": "主页",
        "iconPath": "images/tabBar/icon_index.png",
        "selectedIconPath": "images/tabBar/icon_index_selected.png"
      },
      {
        "pagePath": "pages/my/my",
        "text": "我的",
        "iconPath": "images/tabBar/icon_my.png",
        "selectedIconPath": "images/tabBar/icon_my_selected.png"
      }
  ]
},

2.3 页面配置

每一个小程序页面也可以使用同名 .json 文件来对本页面的窗口表现进行配置,页面中配置项会覆盖app.jsonwindow 中相同的配置项。

{
  "navigationBarBackgroundColor": "#ffffff",
  "navigationBarTextStyle": "black",
  "navigationBarTitleText": "小程序名称",
  "backgroundColor": "#eeeeee",
  "backgroundTextStyle": "light"
}

3 app.js文件

在这里插入图片描述

globalData: {
	url: "http://127.0.0.1/",
},

onLaunch() 函数:默认程序打开后一定执行的功能

4 综合小案例

这里配置两个文件:app.json,index.wxml

4.1 app.json

{
  "pages": [
    "pages/index/index",
    "pages/my/my"
  ],
  "window": {
    "backgroundColor": "#F6F6F6",
    "backgroundTextStyle": "light",
    "navigationBarBackgroundColor": "#F6F6F6",
    "navigationBarTitleText": "小程序名称",
    "navigationBarTextStyle": "black"
  },
  "sitemapLocation": "sitemap.json",
  "style": "v2",
  "tabBar": {
    "list": [
      {
        "pagePath": "pages/index/index",
        "text": "主页",
        "iconPath": "images/tabBar/icon_index.png",
        "selectedIconPath": "images/tabBar/icon_index_selected.png"
      },
      {
        "pagePath": "pages/my/my",
        "text": "我的",
        "iconPath": "images/tabBar/icon_my.png",
        "selectedIconPath": "images/tabBar/icon_my_selected.png"
      }
    ]
  }
}

4.2 index.wxml

<view>
	你真棒
</view>

在这里插入图片描述

欢迎加入博主官方QQ群交流: 779133600

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

有勇气的牛排

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值