小程序 「项目架构」

weChat

一、微信小程序

.js 脚本文件
.json 配置文件
.wxss 样式表文件

二、文件结构

主体组成:

  • 必须放在项目根目录
文件 说明 备注
app.js 小程序逻辑
app.json 小程序公共设置
app.wxss 小程序公共样式表 .

页面组成:

  • 必须具有相同的路径与文件名
文件 说明 备注
js 页面逻辑
wxml 页面结构
wxss 页面样式表
json 页面配置 .

三、配置

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

app.json

字段 类型 必填 说明 备注
pages String Array 页面路径
window Object 默认页面的窗口
tabBar Object 底部tab
networkTimeout Object 网络超时时间
dubug Boolean 是否开启debug模式 .

pages

指定页面组成。

//1.每一项代表对应页面的【路径+文件名】信息
//2.数组的第一项代表小程序的初始页面
//3.小程序中新增/减少页面,都需要对 pages 数组进行修改
//4.文件名不需要写文件后缀

{
  "pages":[
    "pages/index/index"
    "pages/logs/logs"
  ]
}

window

设置小程序的状态栏、导航条、标题、窗口背景色。

{
  "window":{
    "navigationBarBackgroundColor": "#ffffff",
    "navigationBarTextStyle": "black",
    "navigationBarTitleText": "微信接口功能演示",
    "backgroundColor": "#eeeeee",
    "backgroundTextStyle": "light"
  }
}
属性 类型 默认值 说明 备注
navigationBarBackgroundColor HexColor #000000 导航栏背景�色
navigationBarTextStyle String white 导航栏标题样式 black/white
navigationBarTitleText String 导航栏标题
backgroundColor HexColor #ffffff 窗口背景颜色
backgroundTextStyle String dark 下拉背景字体loading样式 dark/light
enablePullDownRefresh Boolean false 是否开启下拉刷新 .

tabBar

指定标签栏组成,以及切换时显示的页面

页面跳转(wx.navigateTo)

页面重定向(wx.redirectTo)

//只能配置最少2个、最多5个 tab

"tabBar":{
    "color": "#ffffff",
    "selectedColor": "#ffffff",
    "backgroundColor": "#ffffff",
    "borderStyle": "black",
    "list": [{
        "pagePath": "pages/index/index",
        "text": "首页",
        "iconPath": "",
        "selectedIconPath": ""
      },{
        "pagePath": "pages/logs/logs",
        "text": "我的",
        "iconPath": "",
        "selectedIconPath": ""
      }],
    "position": "bottom"
 }
属性 类型 必填 默认值 说明 备注
color HexColor 标题默认颜色
selectedColor HexColor 标题选中颜色
backgroundColor HexColor 背景色
borderStyle String black 边框的颜色 black/white
list Array 标签配置 最少2个、最多5个
position String bottom 可选值 bottom、top bottom/top
list

数组中的每个项都是一个对象

属性 类型 必填 说明 备注
pagePath String 页面路径
text String 标题
iconPath String 默认图片 40KB, 81x81px
selectedIconPath String 选中图片 40KB, 81x81px

networkTimeout

设置网络请求的超时时间

属性 类型 必填 默认值 说明 备注
request Number 60000 wx.request 超时时间 毫秒
connectSocket Number 60000 wx.connectSocket 超时时间 毫秒
uploadFile Number 60000 wx.uploadFile 超时时间 毫秒
downloadFile Number 60000 wx.downloadFile 超时时间 毫秒

debug

设置开发者工具中开启 debug 模式

Page的注册页面路由数据更新事件触发

page.json

设置本页面的窗口

{
  "navigationBarBackgroundColor": "#ffffff",
  "navigationBarTextStyle": "black",
  "navigationBarTitleText": "微信接口功能演示",
  "backgroundColor": "#eeeeee",
  "backgroundTextStyle": "light"
}
属性 类型 默认值 说明 备注
navigationBarBackgroundColor HexColor # 000000 导航栏背景颜色
navigationBarTextStyle String white 导航栏标题颜色 black/white
navigationBarTitleText String 导航栏标题文字内容
backgroundColor HexColor #ffffff 窗口的背景色
backgroundTextStyle String dark 下拉背景字体、loading 图的样式 dark/light
enablePullDownRefresh Boolean false 是否开启下拉刷新
disableScroll Boolean false 页面整体不能上下滚动 只在 page.json 中有效
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 134,991评论 19 139
  • 昨天看了一下微信小程序官方文档,总结一下自己学习的个人心得. 首先从官方文档给的框架说起,微信小程序官方文档给出了...
    Mr大大大阅读 47,270评论 9 68
  • 最近做了一个投票的微信小程序,开发过程主要还是参考官方文档:https://mp.weixin.qq.com/de...
    june5253阅读 22,061评论 1 11
  • 前言: 前一章简述了微信小程序的注册,既然注册了,那么肯定要开发微信小程序了。 俗话说的好:工欲善其事必先...
    Smile__EveryDay阅读 3,732评论 1 12
  • 微信小程序在无论在功能、文档及相关支持方面,都是优于前面几种微信账号类型,它提供了很多原生程序才有的接口,使得我们...
    未央大佬阅读 2,338评论 0 12