How to set global variables (code) in WeChat applet

不言
Release: 2018-08-11 17:37:55
Original
9662 people have browsed it

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: '',
        }  
    }    
})
Copy after login

Then write

Page({
   onLoad:function(r){
 
   getApp().globalData.user='Geek'
   }
 
   console.log('user的值是:' + getApp().globalData.user)
 
})
Copy after login
## 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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!