Home >WeChat Applet >Mini Program Development >How to set global variables (code) in WeChat applet

How to set global variables (code) in WeChat applet

不言
不言Original
2018-08-11 17:37:559716browse

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn