温馨提示×

微信小程序页面如何获取全局变量

小新
611
2021-03-19 18:15:26
栏目: 云计算

微信小程序页面如何获取全局变量

微信小程序页面获取全局变量的案例:

app.js文件代码:

App({

globalData{

test:"hello world"

}

})

index.js文件代码:

var app =getApp()

Page({

test:null

})

onLoad: function (options) {

this.setData({

test:app.globalData.test

})

}

index.wxml文件代码:

<view>{{test}}</view>

0