App程序注册
Page页面注册
getApp获取App实例
getCurrentPages获取当前页面栈
1、App方法
https://developers.weixin.qq.com/miniprogram/dev/framework/app-service/app.html
一个小程序只有1个App实例,全部页面共享,可以通过getApp方法获取全局唯一的App实例,定义全局变量方法:
调用全局变量:
2、Page方法
https://developers.weixin.qq.com/miniprogram/dev/framework/app-service/page.html
调用自定义方法需要使用this
this.方法名称()
3、getApp方法
用于获取全局唯一的App实例,针对某个page const app = getApp()
4、getCurrentPages方法
5、模块
将公用程序抽离 成一个独立的js文件,称为模块
模块通过module.exports或者exports对外暴露接口 ,exports是module.exports的一个引用
一般推荐使用module.exports
操作:在小程序根目录下创建util/util.js并写入代码
在使用的逻辑页面中引入公共方法: