Home >WeChat Applet >Mini Program Development >How to set global variables (code) in WeChat applet
The content of this article is about how to set global variables (code) in WeChat applet. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.
There is app.js in the WeChat applet. We can set global variables in this.
App({ globalData:{ user:'', data:{ a: '', b: '', } } })
Then write
Page({ onLoad:function(r){ getApp().globalData.user='Geek' } console.log('user的值是:' + getApp().globalData.user) })## in the js page that uses global variables. # Related recommendations:
How to call the local interface in the WeChat applet
How to implement synchronous requests in the WeChat applet
A brief introduction to block packaging elements in mini programs
The above is the detailed content of How to set global variables (code) in WeChat applet. For more information, please follow other related articles on the PHP Chinese website!