In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
本文小编为大家详细介绍"微信小程序开发怎么配置",内容详细,步骤清晰,细节处理妥当,希望这篇"微信小程序开发怎么配置"文章能帮助大家解决疑惑,下面跟着小编的思路慢慢深入,一起来学习新知识吧。
微信小程序开发:简单配置教程包括对小程序全局配置,包括page,window等基本的设置。
1.配置
app.json文件用来对微信小程序进行全局配置,决定页面文件的路径、窗口表现、设置网络超时时间、设置多 tab 等。
属性类型必填描述pagesString Array是设置页面路径windowObject否设置默认页面的窗口表现tabBarObject否设置底部 tab 的表现networkTimeoutObject否设置网络超时时间debugBoolean否设置是否开启 debug 模式
1.1 pages
接受一个数组,每一项都是字符串,来指定小程序由哪些页面组成。每一项代表对应页面的【路径+文件名】信息,数组的第一项代表小程序的初始页面。小程序中新增/减少页面,都需要对 pages 数组进行修改。
文件名不需要写文件后缀,因为框架会自动去寻找路径下 .json, .js, .wxml, .wxss 四个文件进行整合。
eg:
{ "pages":[ "pages/index/index", "pages/logs/logs" ]}
1.2 window
用于设置小程序的状态栏、导航条、标题、窗口背景色。
属性类型默认值描述navigationBarBackgroundColorHexColor#000000导航栏背景颜色,如"#000000"navigationBarTextStyleStringwhite导航栏标题颜色,仅支持 black/whitenavigationBarTitleTextString导航栏标题文字内容backgroundColorHexColor#ffffff窗口的背景色backgroundTextStyleStringdark下拉背景字体、loading 图的样式,仅支持 dark/lightenablePullDownRefreshBooleanfalse是否开启下拉刷新,详见页面相关事件处理函数。onReachBottomDistanceNumber50页面上拉触底事件触发时距页面底部距离,单位为px
注:HexColor(十六进制颜色值),如"#ff00ff"
eg:
{ "window":{ "navigationBarBackgroundColor": "#ffffff", "navigationBarTextStyle": "black", "navigationBarTitleText": "微信接口功能演示", "backgroundColor": "#eeeeee", "backgroundTextStyle": "light" }}
1.3 tabBar
如果小程序是一个多 tab 应用(客户端窗口的底部或顶部有 tab 栏可以切换页面),可以通过 tabBar 配置项指定 tab 栏的表现,以及 tab 切换时显示的对应页面。
Tip:
当设置 position 为 top 时,将不会显示 icontabBar 中的 list 是一个数组,只能配置最少2个、最多5个 tab,tab 按数组的顺序排序。
属性说明:
属性类型必填默认值描述colorHexColor是tab 上的文字默认颜色selectedColorHexColor是tab 上的文字选中时的颜色backgroundColorHexColor是tab 的背景色borderStyleString否blacktabbar上边框的颜色, 仅支持 black/whitelistArray是tab 的列表,详见 list 属性说明,最少2个、最多5个 tabpositionString否bottom可选值 bottom、top
其中 list 接受一个数组,数组中的每个项都是一个对象,其属性值如下:
属性类型必填说明pagePathString是页面路径,必须在 pages 中先定义textString是tab 上按钮文字iconPathString否图片路径,icon 大小限制为40kb,建议尺寸为 81px * 81px,当 postion 为 top 时,此参数无效,不支持网络图片selectedIconPathString否选中时的图片路径,icon 大小限制为40kb,建议尺寸为 81px * 81px ,当 postion 为 top 时,此参数无效
eg: "tabBar": { "color": "#7A7E83", "selectedColor": "#3cc51f", "backgroundColor" : "#F7F7FA", "borderStyle": "white", "list": [{ "pagePath": "pages/word/word", "text": "背词", "iconPath": "images/home.png", "selectedIconPath": "images/home-selected.png" } 1.4 networkTimeout
可以设置各种网络请求的超时时间。
属性说明:
属性类型必填说明requestNumber否wx.request的超时时间,单位毫秒,默认为:60000connectSocketNumber否wx.connectSocket的超时时间,单位毫秒,默认为:60000uploadFileNumber否wx.uploadFile的超时时间,单位毫秒,默认为:60000downloadFileNumber否wx.downloadFile的超时时间,单位毫秒,默认为:60000
1.5 debug
可以在开发者工具中开启 debug 模式,在开发者工具的控制台面板,调试信息以 info 的形式给出,其信息有Page的注册,页面路由,数据更新,事件触发 。 可以帮助开发者快速定位一些常见的问题。
1.6 page.json
每一个小程序页面也可以使用.json文件来对本页面的窗口表现进行配置。 页面的配置比app.json全局配置简单得多,只是设置 app.json 中的 window 配置项的内容,页面中配置项会覆盖 app.json 的 window 中相同的配置项。
页面的.json只能设置 window 相关的配置项,以决定本页面的窗口表现,所以无需写 window 这个键,如:
属性类型默认值描述navigationBarBackgroundColorHexColor#000000导航栏背景颜色,如"#000000"navigationBarTextStyleStringwhite导航栏标题颜色,仅支持 black/whitenavigationBarTitleTextString导航栏标题文字内容backgroundColorHexColor#ffffff窗口的背景色backgroundTextStyleStringdark下拉背景字体、loading 图的样式,仅支持 dark/lightenablePullDownRefreshBooleanfalse是否开启下拉刷新,详见页面相关事件处理函数。disableScrollBooleanfalse设置为 true 则页面整体不能上下滚动;只在 page.json 中有效,无法在 app.json 中设置该项onReachBottomDistanceNumber50页面上拉触底事件触发时距页面底部距离,单位为px
eg:
{ "navigationBarBackgroundColor": "#ffffff", "navigationBarTextStyle": "black", "navigationBarTitleText": "微信接口功能演示", "backgroundColor": "#eeeeee", "backgroundTextStyle": "light"}
下面展示下项目中的app.json的完整样式:
{ "pages":[ "pages/word/word", "pages/search/search", "pages/settings/settings", "pages/search/detail/detail", "pages/settings/clause/clause", "pages/settings/help/help", "pages/settings/feedback/feedback", "pages/note/index/index", "pages/note/create/index", "pages/note/edit/index", "pages/intro/intro", "pages/intro/trick/trick", "pages/intro/recommend/recommend", "pages/intro/saying/saying" ], "tabBar": { "color": "#7A7E83", "selectedColor": "#3cc51f", "backgroundColor" : "#F7F7FA", "borderStyle": "white", "list": [{ "pagePath": "pages/word/word", "text": "背词", "iconPath": "images/home.png", "selectedIconPath": "images/home-selected.png" }, { "pagePath": "pages/search/search", "text": "查词", "iconPath": "images/search.png", "selectedIconPath": "images/search-selected.png" }, { "pagePath": "pages/intro/intro", "text": "方法", "iconPath": "images/intro.png", "selectedIconPath": "images/intro-selected.png" }, { "pagePath": "pages/note/index/index", "text": "笔记", "iconPath": "images/note.png", "selectedIconPath": "images/note-selected.png" }, { "pagePath": "pages/settings/settings", "text": "设置", "iconPath": "images/settings.png", "selectedIconPath": "images/settings-selected.png" }] }, "window":{ "backgroundTextStyle":"light", "backgroundColor": "#EFEFF4", "navigationBarBackgroundColor": "#2C2D31", "navigationBarTitleText": "佑米单词", "navigationBarTextStyle":"white", "enablePullDownRefresh": true }}读到这里,这篇"微信小程序开发怎么配置"文章已经介绍完毕,想要掌握这篇文章的知识点还需要大家自己动手实践使用过才能领会,如果想了解更多相关内容的文章,欢迎关注行业资讯频道。
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.