微信小程序開發(fā)app.json全局配置實戰(zhàn)指南
JSON 是一種數(shù)據格式,在實際開發(fā)中,JSON 總是以配置文件的形式出現(xiàn)。
app.json 是當前小程序的全局配置,可以通過app.json對小程序項目進行設置所有頁面路徑、窗口外觀、界面表現(xiàn)、底部 tab 等。
{ "pages": [ "pages/index/index", "pages/mine/mine", "pages/play/play", "pages/mycard/mycard", "pages/Record/Record", "pages/prize/prize", "pages/details/details", "pages/lottery/lottery", "pages/ar/ar" ], "window": { "backgroundTextStyle": "light", "navigationBarBackgroundColor": "#fff", "navigationBarTitleText": "我是展示標題", "navigationBarTextStyle": "black" }, "tabBar": { "backgroundColor": "#FFFFFF", "color": "#181818", "selectedColor": "#221415", "list": [ { "pagePath": "pages/ar/ar", "iconPath": "images/tabbar/arg.png", "selectedIconPath": "images/tabbar/AR.png", "text": "AR" }, { "pagePath": "pages/play/play", "iconPath": "images/tabbar/play.png", "selectedIconPath": "images/tabbar/playg.png", "text": "玩法" }, { "pagePath": "pages/index/index", "iconPath": "images/tabbar/mine.png", "selectedIconPath": "images/tabbar/my.png", "text": "我的" } ] }, "usingComponents": { "van-image": "@vant/weapp/image/index", "van-field": "@vant/weapp/field/index", "van-divider": "@vant/weapp/divider/index", "van-button": "@vant/weapp/button/index", "van-toast": "@vant/weapp/toast/index" }, "requiredPrivateInfos": [ "getLocation" ], "permission": { "scope.userLocation": { "desc": "你的位置信息將用于小程序位置接口的效果展示" } }, "sitemapLocation": "sitemap.json" }
pages配置項是一個數(shù)組,主要用于記錄頁面路徑。
第一項路徑是小程序默認進入的首頁
"pages": [ "pages/index/index", "pages/mine/mine", "pages/play/play", "pages/mycard/mycard", "pages/Record/Record", "pages/prize/prize", "pages/details/details", "pages/lottery/lottery", "pages/ar/ar" ],
window配置項主要用于更改所有頁面的狀態(tài)欄、導航欄、標題、窗口背景色等。
"window": { "backgroundTextStyle": "light", "navigationBarBackgroundColor": "#fff", "navigationBarTitleText": "我是展示標題", "navigationBarTextStyle": "black" },
tarBar如果小程序是一個多 tab 應用(客戶端窗口的底部或頂部有 tab 欄可以切換頁面),可以通過 tabBar 配置項指定 tab 欄的表現(xiàn),以及 tab 切換時顯示的對應頁面。
"tabBar": { "backgroundColor": "#FFFFFF", "color": "#181818", "selectedColor": "#221415", "list": [ { "pagePath": "pages/ar/ar", "iconPath": "images/tabbar/arg.png", "selectedIconPath": "images/tabbar/AR.png", "text": "AR" }, { "pagePath": "pages/play/play", "iconPath": "images/tabbar/play.png", "selectedIconPath": "images/tabbar/playg.png", "text": "玩法" }, { "pagePath": "pages/index/index", "iconPath": "images/tabbar/mine.png", "selectedIconPath": "images/tabbar/my.png", "text": "我的" } ] },
usingComponents
在 app.json 中聲明的自定義組件視為全局自定義組件,在小程序內的頁面或自定義組件中可以直接使用而無需再聲明。建議僅在此聲明幾乎所有頁面都會用到的自定義組件。
注1:全局自定義組件會視為被所有頁面依賴,會在所有頁面啟動時進行初始化,影響啟動性能且會占用主包大小。只被個別頁面或分包引用的自定義組件應盡量在頁面配置中聲明。 注2:在全局聲明使用率低的自定義組件會大幅影響按需注入的效果。
我在這里用的是vant的微信小程序組件庫https://youzan.github.io/vant-weapp/#/home(Vant Weapp)
"usingComponents": { "van-image": "@vant/weapp/image/index", "van-field": "@vant/weapp/field/index", "van-divider": "@vant/weapp/divider/index", "van-button": "@vant/weapp/button/index", "van-toast": "@vant/weapp/toast/index" },
requiredPrivateInfos
自 2022 年 7 月 14 日后發(fā)布的小程序,使用以下8個地理位置相關接口時,需要聲明該字段,否則將無法正常使用。2022 年 7 月 14 日前發(fā)布的小程序不受影響。
申明需要使用的地理位置相關接口,類型為數(shù)組。目前支持以下項目:
getFuzzyLocation: 獲取模糊地理位置
getLocation: 獲取精確地理位置
onLocationChange: 監(jiān)聽試試地理位置變化事件
startLocationUpdate: 接收位置消息(前臺)
startLocationUpdateBackground: 接收位置消息(前后臺)
chooseLocation: 打開地圖選擇位置
choosePoi: 打開 POI 列表選擇位置
chooseAddress: 獲取用戶地址信息
"requiredPrivateInfos": [ "getLocation" ],
permission
微信客戶端 7.0.0 及以上版本支持
小程序接口權限相關設置。字段類型為 Object,結構為:
"requiredPrivateInfos": [ "getLocation" ],
sitemapLocation
指明 sitemap.json 的位置;默認為 'sitemap.json' 即在 app.json 同級目錄下名字的 sitemap.json 文件
"sitemapLocation": "sitemap.json"
總結
到此這篇關于微信小程序開發(fā)app.json全局配置實戰(zhàn)指南的文章就介紹到這了,更多相關微信小程序app.json全局配置內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
用Golang運行JavaScript的實現(xiàn)示例
這篇文章主要介紹了用Golang運行JavaScript的實現(xiàn)示例,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2019-11-11javascript使用正則控制input輸入框允許輸入的值方法大全
在做項目的時候,我們經常會遇到控制input輸入框允許輸入的值為數(shù)字,字母,漢字或者混排的情況,那么我們怎么來處理呢,下面我們就來探討怎么通過用javascript正則來實現(xiàn)2014-06-06xml分頁+ajax請求數(shù)據源+dom取結果實例代碼
最近做的一個項目里的某個小功能,主要是為了方便選擇數(shù)據 演示地址:由于有惡意程序,所以去掉地址2008-10-10