类别:uni-app文档

日期:2020-11-19 浏览:2246 评论:0

  pages.json

pages.json 文件用来对 uni-app 进行全局配置,决定页面文件的路径、窗口表现、设置多 tab 等。

   pages.json 配置项列表

globalStyle Object 否 设置默认页面的窗口表现
pages Object Array 是 设置页面路径及窗口表现
tabBar Object 否 设置底部 tab 的表现
condition Object 否 启动模式配置

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

{
  "pages": [{
    "path": "pages/component/index",
    "style": {
      "navigationBarTitleText": "组件"
    }
  }, {
    "path": "pages/API/index",
    "style": {
      "navigationBarTitleText": "接口"
    }
  }, {
    "path": "pages/component/view/index",
    "style": {
      "navigationBarTitleText": "view"
    }
  }],
  "globalStyle": {
    "navigationBarTextStyle": "black",
    "navigationBarTitleText": "演示",
    "navigationBarBackgroundColor": "#F8F8F8",
    "backgroundColor": "#F8F8F8"
  },
  "tabBar": {
    "color": "#7A7E83",
    "selectedColor": "#3cc51f",
    "borderStyle": "black",
    "backgroundColor": "#ffffff",
    "list": [{
      "pagePath": "pages/component/index",
      "iconPath": "static/image/icon_component.png",
      "selectedIconPath": "static/image/icon_component_HL.png",
      "text": "组件"
    }, {
      "pagePath": "pages/API/index",
      "iconPath": "static/image/icon_API.png",
      "selectedIconPath": "static/image/icon_API_HL.png",
      "text": "接口"
    }]
  }}

  globalStyle

用于设置应用的状态栏、导航条、标题、窗口背景色等。

navigationBarBackgroundColor HexColor #000000 导航栏背景颜色
navigationBarTextStyle String white 导航栏标题颜色,仅支持 black/white
navigationBarTitleText String 导航栏标题文字内容
navigationStyle String default 导航栏样式,仅支持 default/custom。
backgroundColor HexColor #ffffff 窗口的背景色 微信小程序

注意:navigationStyle 只在 pages.json->globalStyle 中设置生效。开启 custom 后,所有窗口均无导航栏。

  pages

接收一个数组,来指定应用由哪些页面组成。每一项代表对应页面的信息,应用中新增/减少页面,都需要对 pages 数组进行修改。

文件名不需要写后缀,框架会自动寻找路径下的页面资源。

注意:pages节点的第一项为应用入口页(即首页)。

代码示例:

开发目录为:

pages/pages/index/index.vue
pages/login/login.vue
mainfest.json
pages.json

则需要在 pages.json 中填写

{
  "pages": [{
      "index": {
        "path": "pages/index/index"
      }
    },
    {
      "login": {
        "path": "pages/login/login"
      }
    }
  ]}

  pages.style

用于设置每个页面的状态栏、导航条、标题、窗口背景色等。

navigationBarBackgroundColor HexColor #000000 导航栏背景颜色,如"#000000"
navigationBarTextStyle String white 导航栏标题颜色,仅支持 black/white
navigationBarTitleText String 导航栏标题文字内容
backgroundColor HexColor #ffffff 窗口的背景色 微信小程序
backgroundTextStyle String dark 下拉 loading 的样式,仅支持 dark/light
enablePullDownRefresh Boolean false 是否开启下拉刷新,详见页面相关事件处理函数
onReachBottomDistance Number 50 页面上拉触底事件触发时距页面底部距离,单位为px
navigationStyle String default 导航栏样式,仅支持 default/custom。custom 模式可自定义导航栏,只保留右上角胶囊状的按钮。 微信小程序
backgroundColorTop String #ffffff 顶部窗口的背景色。 微信小程序且为 iOS
backgroundColorBottom String #ffffff 底部窗口的背景色。 微信小程序且为 iOS

代码示例:

{
  "pages": [{
      "index": {
        "path": "pages/index/index",
        "style": {
            "navigationBarTitleText": "首页",//设置页面标题文字
          "enablePullDownRefresh":true//开启下拉刷新
        }
      }
    },
    ...
  ]}

  tabBar

如果应用是一个多 tab 应用,可以通过 tabBar 配置项指定 tab 栏的表现,以及 tab 切换时显示的对应页。

 Tips

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

color HexColor 是 tab 上的文字默认颜色
selectedColor HexColor 是 tab 上的文字选中时的颜色
backgroundColor HexColor 是 tab 的背景色
borderStyle String 否 black tabbar 上边框的颜色,仅支持 black/white
list Array 是 tab 的列表,详见 list 属性说明,最少2个、最多5个 tab
position String 否 bottom 可选值 bottom、top

其中 list 接收一个数组,数组中的每个项都是一个对象,其属性值如下:

pagePath String 是 页面路径,必须在 pages 中先定义
text String 是 tab 上按钮文字
iconPath String 否 图片路径,icon 大小限制为40kb,建议尺寸为 81px * 81px,当 postion 为 top 时,此参数无效,不支持网络图片
selectedIconPath String 否 选中时的图片路径,icon 大小限制为40kb,建议尺寸为 81px * 81px ,当 postion 为 top 时,此参数无效

  condition

启动模式配置,仅开发期间生效,用于模拟直达页面的场景,如:小程序转发后,用户点击所打开的页面。

属性说明

current Number 是 当前激活的模式,list节点的索引值
list Array 是 启动模式列表

list说明:

name String 是 启动模式名称

path String 是 启动页面路径

query String 否 启动参数,可在页面的 onLoad 函数里获得

注意: 在5+app里真机运行可直接打开配置的页面,微信开发者工具里需要手动改变编译模式:
代码示例:

"condition": { //模式配置,仅开发期间生效
    "current": 0, //当前激活的模式(list 的索引项)
    "list": [{
            "name": "swiper", //模式名称
            "path": "pages/component/swiper/swiper", //启动页面,必选
            "query": "interval=4000&autoplay=false" //启动参数,在页面的onLoad函数里面得到。
        },
        {
            "name": "test",
            "path": "pages/component/switch/switch"
        }
    ]}

自行测试
1、改变导航背景颜色及标题
2、创建页面
3、创建 tabbar


本文标题:uni-app 配置文件 - pages.json
本文链接:https://vtzw.com/post/441.html
作者授权:除特别说明外,本文由 零一 原创编译并授权 零一的世界 刊载发布。
版权声明:本文不使用任何协议授权,您可以任何形式自由转载或使用。
 您阅读本篇文章共花了: 

 可能感兴趣的文章

评论区

发表评论 / 取消回复

必填

选填

选填

◎欢迎讨论,请在这里发表您的看法及观点。