小程序配置
JSON配置
app.json
是当前小程序的全局配置,包括了小程序的所有页面路径、界面表现、网络超时时间、底部 tab 等。
点击查看代码
{
"pages":[//页面路由,在这里添加路由可以自动生成对应文件
"pages/index/index",
"pages/logs/logs",
"pages/demo01/demo01"
],
"window":{//定义小程序所有页面的顶部背景颜色,文字颜色定义等
//下拉 loading 的样式,仅支持 dark / light
"backgroundTextStyle":"light",
//导航栏的样式
"navigationBarBackgroundColor": "#fff",
"navigationBarTitleText": "WeChat",
"navigationBarTextStyle":"black"
},
"style": "v2",
"sitemapLocation": "sitemap.json"
}
工具配置 project.config.json
个性化配置,例如界面颜色、编译配置等等
点击查看代码
"miniprogramRoot": "miniprogram/", //指定小程序源码的目录(需为相对路径)
"compileType": "miniprogram",//编译类型,miniprogram当前为普通小程序项目。plugin当前为小程序插件项目
页面配置 page.json
对每个页面进行单独配置
sitemap 配置
⽤于配置⼩程序及其⻚⾯是否允许被微信索引
生命周期函数
onLaunch
onlaunch:当小程序初始化完成时,会触发 onLaunch(全局只触发一次)(app.js);
--获取设备信息
app.js
点击查看代码
App<IAppOption>({
globalData: {
tabBarHeight: 0,
navBarHeight: 0,
statusBarHeight: 0
},
onLaunch() {
const systemInfo = wx.getSystemInfoSync();
this.globalData.tabBarHeight = systemInfo.screenHeight - systemInfo.windowHeight - systemInfo.statusBarHeight; (px)
this.globalData.navBarHeight = (systemInfo.statusBarHeight + 44) * 2;
this.globalData.statusBarHeight = systemInfo.statusBarHeight * 2;
}
导入导出
点击查看代码
导出
function untilFun(){
console.log("这是要导出的公共函数呀!")
}
module.exports = { //这里是要导出的函数
untilFun
}
导入
const untilFun = require('../../until') //放置公共函数的文件路径
本文来自博客园,作者:Kira的学习笔记,转载请注明原文链接:https://www.cnblogs.com/kira2022/p/17899583.html
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
· .NET周刊【3月第1期 2025-03-02】