当前位置:网站首页>Wechat applet: use of global state variables
Wechat applet: use of global state variables
2022-06-13 06:08:00 【HaanLen】
Definition of global variables
stay app.ts Set in file ,globalData Object is to store global variables .
// app.ts
App<IAppOption>({
globalData: {
userName: 'Yan'
},
onLaunch() {
// Demonstrate local storage capabilities
const logs = wx.getStorageSync('logs') || []
logs.unshift(Date.now())
wx.setStorageSync('logs', logs)
// Sign in
wx.login({
success: res => {
console.log(res.code)
// send out res.code Go backstage to exchange openId, sessionKey, unionId
},
})
},
})
Set the value of the global variable
<!--pages/study/index.wxml-->
<text>pages/study/index.wxml</text>
<view>{
{text}}</view>
<button type="primary" bindtap="getInfo"> Click for information </button>
<view>yici</view>
<button type="primary" bindtap="setGlobal"> Set global variables </button>
setGlobal(){
app1.globalData.userName = 'Hello Yanpppp'
}
Use of global variables
<!--pages/note.wxml-->
<text>pages/note.wxml</text>
<view>{
{text}}</view>
<view>ooo</view>
// pages/note.ts
const appNote = getApp();
Page({
/** * Initial data of the page */
data: {
text: appNote?.globalData.userName,
},
/** * Life cycle function -- Monitor page loading */
onLoad() {
},
/** * Life cycle function -- Listening page first rendering completed */
onReady() {
},
/** * Life cycle function -- Monitor page display */
onShow() {
},
/** * Life cycle function -- Monitor page hidden */
onHide() {
},
/** * Life cycle function -- Monitor page uninstall */
onUnload() {
},
/** * Page related event handler -- Monitor user pull-down action */
onPullDownRefresh() {
},
/** * Handling function of page pull bottom event */
onReachBottom() {
},
/** * Users click the upper right corner to share */
onShareAppMessage() {
}
})
边栏推荐
- Self summarizing
- Wechat applet jumps to H5 page with parameters
- Leetcode- reverse string - simple
- Leetcode minimum absolute difference of binary search tree simple
- @The detailed explanation of configurationproperties and the problem that all properties of the entity bean modified by this annotation are null after injection are solved
- Echart柱状图:echart实现堆叠柱状图
- FusionPBX 安装 —— 筑梦之路
- Fichier local second Search Tool everything
- Concurrent programming -- source code analysis of thread pool
- [turn] explain awk (1)__ Awk Basics_ Options_ Program segment parsing and examples
猜你喜欢

Feel the power of shardingsphere JDBC through the demo

Echart histogram: echart implements stacked histogram

MySQL trigger

推荐扩容工具,彻底解决C盘及其它磁盘空间不够的难题
![[spark]spark introductory practical series_ 8_ Spark_ Mllib (upper)__ Introduction to machine learning and sparkmllib](/img/39/501b9b8962b03cfc59e2636f88ee93.jpg)
[spark]spark introductory practical series_ 8_ Spark_ Mllib (upper)__ Introduction to machine learning and sparkmllib

The SQL file of mysql8.0 was imported into version 5.5. There was a pit

Echart line chart: multiple line charts show only one line at a time

You still can't remotely debug idea? Come and have a look at my article. It's easy to use

Misunderstanding of tongweb due to ease of use

【ONE·Data || 带头双向循环链表简单实现】
随机推荐
Data conversion analysis tool
推荐扩容工具,彻底解决C盘及其它磁盘空间不够的难题
Minimum spanning tree (prim+kruskal) learning notes (template +oj topic)
Printf function
1016 part a+b (15 points)
不在以下合法域名列表中,微信小程序解决办法
Echart柱状图:echart实现堆叠柱状图
The title of the WebView page will be displayed in the top navigation bar of the app. How to customize
Echart histogram: X-axis displays value, Y-axis displays category
万能播放器 PotPlayer 的下载与安装,直播流 m3u8 导入
微信小程序:基础复习
Shardingsphere JDBC < bind table > avoid join Cartesian product
After MySQL is installed, enter the "net start MySQL" command, and an error is reported that "net" is neither an internal or external command nor a runnable program
Shardingsphere JDBC exception: no table route info
USB debugging assistant
MySQL stored procedure
Security baseline check script - the road to dream
Time conversion'2015-04-20t11:12:00.000+0000 '
Leetcode- reverse vowels in string - simple
MySQL trigger