微信小程序 模块化


当前第2页 返回上一页

通过全局函数 getApp 可以获取全局的应用实例,如果需要全局的数据可以在 App() 中设置,如:

// app.js
App({
  globalData: 1
})
// a.js
// The localValue can only be used in file a.js.
var localValue = 'a'
// Get the app instance.
var app = getApp()
// Get the global data and change it.
app.globalData++
// b.js
// You can redefine localValue in file b.js, without interference with the localValue in a.js.
var localValue = 'b'
// If a.js it run before b.js, now the globalData shoule be 2.
console.log(getApp().globalData)



标签:微信小程序

返回前面的内容

相关阅读 >>

sdk数据库 collection聚合操作

微信小程序 小程序简介

微信小程序api 绘图closepath(关闭一个路径)

微信小程序api 绘图stroke(对当前路径进行描边)

微信小程序云开发服务端数据库api 统计集合记录数

微信小程序云开发服务端数据库api 查询指令

sdk数据库 command查询表达式操作符

微信小程序开放数据 ad

微信小程序云开发服务端数据库api collection.skip

微信小程序 工具库类lottie

更多相关阅读请进入《微信小程序》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...