程序开发之学习与基本配置的开始及相关内容

why 146 2024-08-09

如果小程序是一个多 tab 应用(客户端窗口的底部或顶部有 tab 栏可以切换页面),可以通过 tabbar 配置项指定 tab 栏的表现,以及 tab 切换时显示的对应页面。

小程序开始开发及基本设置

  • 微信开发文档:https://developers.weixin.qq.com/miniprogram/dev/

  • -微信开发者工具

    • -:https://developers.weixin.qq.com/miniprogram/dev/devtools/download.html

  • 新建项目

    • image.png

    • image.png

    • image.png

    • image.png

    • 注:有APPID记得填写上,没有就点级小程序,记得勾上普通启动模板;

  • 基本配置

    • 如果小程序是一个多 tab 应用(客户端窗口的底部或顶部有 tab 栏可以切换页面),可以通过 tabbar 配置项指定 tab 栏的表现,以及 tab 切换时显示的对应页面。

    • Tip:
      1.当设置 position 为 top 时,将不会显示 icon
      2.tabBar 中的 list 是一个数组,只能配置最少2个、最多5个 tab,tab 按数组的顺序排序。

    • 例:

    • -

    • 例:

    • 接受一个数组,每一项都是字符串,来指定小程序由哪些页面组成。每一项代表对应页面的【路径+文件名】信息,数组的第一项代表小程序的初始页面。小程序中新增/减少页面,都需要对 pages 数组进行修改。

    • 例:

    • 属性         类型    必填  描述

    • pages        String Array 是   设置页面路径

    • window         Object    否   设置默认页面的窗口表现

    • tabBar          Object    否   设置底部 tab 的表现

    • networkTimeout     Object    否   设置网络超时时间

    • debug     Boolean     否   设置是否开启 debug 模式

    • 配置说明文档:https://developers.weixin.qq.com/miniprogram/dev/framework/config.html

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

    • 以下是一个包含了所有配置选项的 app.json :

      {
        "pages": [    "pages/index/index",    "pages/logs/index"
        ],
        "window": {
          "navigationBarTitleText": "Demo"
        },
        "tabBar": {
          "list": [{
            "pagePath": "pages/index/index",
            "text": "首页"
          }, {
            "pagePath": "pages/logs/logs",
            "text": "日志"
          }]  },
        "networkTimeout": {
          "request": 10000,
          "downloadFile": 10000
        },
        "debug": true}
    • app.json 配置项列表

    • pages 设置页面路径

      {
        "pages":[
          //"pages/页面文件夹名/页面.wxml名",    "pages/index/index",    "pages/logs/logs"
        ]}
    • window 用于设置小程序的状态栏、导航条、标题、窗口背景色。

      "window":{    "backgroundTextStyle":"light",//默认:dark ,下拉 loading 的样式,仅支持 dark/light    "navigationBarBackgroundColor": "#f1f1f1",//默认:#000000, 导航栏背景颜色,如"#000000"
          "navigationBarTitleText": "京东",//   导航栏标题文字内容    "navigationBarTextStyle":"black",//默认:white 导航栏标题颜色,仅支持 black/white    "backgroundColor":"#f1f1f1",//默认:#ffffff,   窗口的背景色
        },
    • tabBar

      "tabBar": {  "position":"bottom",//默认:bottom,  可选值 bottom、top
        "borderStyle":"white",//默认:black, tabbar上边框的颜色, 仅支持 black/white
        "color":"#f10215",//tab 上的文字默认颜色
        "selectedColor": "#f10215",//tab 上的文字选中时的颜色
        "backgroundColor":"#ffffff",//tab 的背景色
        //tab 的列表,详见 list 属性说明,最少2个、最多5个 tab
        "list": [
          {      "pagePath": "pages/index/index", //页面路径,必须在 pages 中先定义
            "text": "首页", //tab 上按钮文字
            "iconPath": "images/index.png", 
              //图片路径,icon 大小限制为40kb,建议尺寸为 81px * 81px,当 postion 为 top 时,此参数无效,不支持网络图片
            "selectedIconPath": "images/index_b.png" 
              //选中时的图片路径,icon 大小限制为40kb,建议尺寸为 81px * 81px ,当 postion 为 top 时,此参数无效
          },
          {      "pagePath": "pages/category/category",      "text": "分类",      "iconPath": "images/category.png",      "selectedIconPath": "images/category_b.png"
          },
          {      "pagePath": "pages/cart/cart",      "text": "购物车",      "iconPath": "images/cart.png",      "selectedIconPath": "images/cart_b.png"
          },
          {      "pagePath": "pages/user/user",      "text": "我的",      "iconPath": "images/user.png",      "selectedIconPath": "images/user_b.png"
          }
        ]
      }

      具体配置请看开发手册:https://developers.weixin.qq.com/miniprogram/dev/framework/config.html


版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:关于小程序代码构成中 json 后缀的 JSON 配置文件详细讲解
下一篇:微信小程序中广告自定义组件之媒体音频播放组件 audio 详解
相关文章

 发表评论

暂时没有评论,来抢沙发吧~