适合用微信小程序、字节跳动小程序。
1.非app.js的页面:
var app = getApp();
app.globalData.userName = "xxx";
2.app.js:
在onLaunch函数中:
注意,var that = this;必须写在onlaunch()开始
onLaunch: function () {
var that = this;
that.globalData.userName = "xxx";
},
适合用微信小程序、字节跳动小程序。
1.非app.js的页面:
var app = getApp();
app.globalData.userName = "xxx";
2.app.js:
在onLaunch函数中:
注意,var that = this;必须写在onlaunch()开始
onLaunch: function () {
var that = this;
that.globalData.userName = "xxx";
},