小程序配置

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') //放置公共函数的文件路径
posted @ 2023-12-14 10:41  Kira的学习笔记  阅读(14)  评论(0编辑  收藏  举报