Rumah > Artikel > applet WeChat > 如何将其他页面的数据存入app.js中
//登录页面
Page({
data:{
username:'',
password:''
}, onShareAppMessage: function () {
return {
title: '登录',
desc: '登录页面!'
}
},
onShow:function(){
var that=this;
wx.getStorage({
key: 'username',
success: function(res) {
console.log(res.data)
that.setData({
username: res.data
})
},
})
wx.getStorage({
key: 'password',
success: function (res) {
console.log(res.data)
that.setData({
password: res.data
})
}
})
},
//app.js
App({
onLaunch: function() {
//调用API从本地缓存中获取数据
var logs = wx.getStorageSync('logs') || []
logs.unshift(Date.now())
wx.setStorageSync('logs', logs)
},
getUserInfo: function(cb) {
var that = this
if (this.globalData.userInfo) {
typeof cb == "function" && cb(this.globalData.userInfo)
} else {
//调用登录接口
wx.getUserInfo({
withCredentials: false,
success: function(res) {
that.globalData.userInfo = res.userInfo
typeof cb == "function" && cb(that.globalData.userInfo)
}
})
}
},
globalData: {
userInfo: null
},
})
Atas ialah kandungan terperinci 如何将其他页面的数据存入app.js中. Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!