关于uniapp配置文件的理解

首先uniapp类似于vue构建项目的时候也是有pages.json这个文件
首先介绍下一个基本的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": "接口"
    }]
  }
}

配置项里面总共有四大类

配置项类型是否为空作用
globalStyleObject设置默认页面的窗口表现
pagesObject Array设置页面路径及窗口表现
tabBarObject设置底部 tab 的表现
conditionObject启动模式配置

然后我们首先介绍
globalStyle
它是用于设置应用的状态栏、导航条、标题、窗口背景色等。
里面的配置就是以下的

配置项类型作用
navigationBarBackgroundColorHexColor (#000000)导航栏背景颜色
navigationBarTextStyleString (white )导航栏标题颜色,仅支持 black/white
navigationBarTitleTextString导航栏标题文字内容
navigationStyleString(default )导航栏样式,仅支持 default/custom
backgroundColorHexColor (#ffffff )窗口的背景色 微信小程序

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

接着是
pages
它接收一个数组,来指定应用由哪些页面组成。每一项代表对应页面的信息,应用中新增/减少页面,都需要对 pages 数组进行修改。
文件名不需要写后缀,框架会自动寻找路径下的页面资源。
它里面一般有两个对象一个是page,另一个是style
在pege里面需要去寻找文件路径

然后style也有配置项

配置项类型作用
navigationBarBackgroundColorHexColor (#000000)导航栏背景颜色
navigationBarTextStyleString (white )导航栏标题颜色,仅支持 black/white
navigationBarTitleTextString导航栏标题文字内容
backgroundColorHexColor (#ffffff )窗口的背景色 微信小程序
backgroundTextStyleString(dark )下拉 loading 的样式,仅支持 dark/light
enablePullDownRefreshBoolean(false )是否开启下拉刷新,详见页面相关事件处理函数
onReachBottomDistanceNumber (50)页面上拉触底事件触发时距页面底部距离,单位为px
navigationStyleString (default )导航栏样式,仅支持 default/custom。custom 模式可自定义导航栏,只保留右上角胶囊状的按钮。 微信小程序
backgroundColorTopString (#ffffff)顶部窗口的背景色。 微信小程序且为 iOS
backgroundColorBottomString (#ffffff)底部窗口的背景色。 微信小程序且为 iOS

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

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

文件实例

tabBar
如果应用是一个多 tab 应用,可以通过 tabBar 配置项指定 tab 栏的表现,以及 tab 切换时显示的对应页。
当设置 position 为 top 时,将不会显示 icon
tabBar 中的 list 是一个数组,只能配置最少2个、最多5个 tab,tab 按数组的顺序排序。
首先他的属性如下

配置项类型是否为空作用
colorHexColortab 上的文字默认颜色
selectedColorHexColortab 上的文字选中时的颜色
backgroundColorHexColortab 的背景色
borderStyleString(black)tabbar 上边框的颜色,仅支持 black/white
listArraytab 的列表,详见 list 属性说明,最少2个、最多5个 tab
positionString(bottom )可选值 bottom、top

其中list是一个数组,数组的每一项都是一个对象,其配置如下

配置项类型是否为空作用
pagePathString页面路径,必须在 pages 中先定义
textStringtab 上按钮文字
iconPathString图片路径,icon 大小限制为40kb,建议尺寸为 81px * 81px,当 postion 为 top 时,此参数无效,不支持网络图片
selectedIconPathString选中时的图片路径,icon 大小限制为40kb,建议尺寸为 81px * 81px ,当 postion 为 top 时,此参数无效

代码实例

"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": "接口"
    }]
  }

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

属性如下

配置项类型是否为空作用
currentNumber当前激活的模式,list节点的索引值
listArray启动模式列表

list属性如下

配置项类型是否为空作用
nameString启动模式名称
pathString启动页面路径
queryString启动参数,可在页面的 onLoad 函数里获得

代码配置如下

"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
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值