十年網(wǎng)站開發(fā)經(jīng)驗(yàn) + 多家企業(yè)客戶 + 靠譜的建站團(tuán)隊(duì)
量身定制 + 運(yùn)營(yíng)維護(hù)+專業(yè)推廣+無憂售后,網(wǎng)站問題一站解決
小編給大家分享一下如何將其他頁(yè)面的數(shù)據(jù)存入app.js中,相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!

//登錄頁(yè)面
Page({
data:{
username:'',
password:''
}, onShareAppMessage: function () {
return {
title: '登錄',
desc: '登錄頁(yè)面!'
}
},
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() {
//調(diào)用API從本地緩存中獲取數(shù)據(jù)
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 {
//調(diào)用登錄接口
wx.getUserInfo({
withCredentials: false,
success: function(res) {
that.globalData.userInfo = res.userInfo
typeof cb == "function" && cb(that.globalData.userInfo)
}
})
}
},
globalData: {
userInfo: null
},
})以上是“如何將其他頁(yè)面的數(shù)據(jù)存入app.js中”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對(duì)大家有所幫助,如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!