微信小程序里面有個(gè)app.js,我們可以在這個(gè)里面設(shè)置全局變量,
全局變量的定義:?
globalData:?{
????????userInfo:?null,
????????tempFilePathslist:?[]
????}
?全局變量的獲?。?/p>
在app.js文件中,直接使用,如:
var gettempFilePathslist = this.globalData.tempFilePathslist
在其他非app.js文件中使用,需要先申明app變量,如
var app = getApp()
var gettempFilePathslist = app.globalData.tempFilePathslist
?
?全局變量的使用:
在app.js文件中
this.globalData.tempFilePathslist= [1,2,3,4,5,6]
在其他非app.js文件中修改:
var app = getApp() /*或定義在頁(yè)面開頭、Page之外 const app = getApp()*/
app.globalData.tempFilePathslist= [1,2,3,4,5,6]
?文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-786360.html
?文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-786360.html
到了這里,關(guān)于微信小程序 使用全局變量的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!