效果圖展示:
我們在index頁面存入數字11,然後在跳轉到新頁面,在將緩存中的11取出渲染到當前頁面。具體代碼如下:
index頁面:
<span style="font-size:24px;">
<view class="btn-area">
<navigator url="../navigator/navigator?title=我是navi">跳轉到新的頁面post情求</navigator>
<navigator url="../redirect/redirect?title=我是red" redirect>跳轉到當前頁面</navigator>
</view>
</span>
<view>
<input style="border:2rpx solid red" placeholder="輸入信息" bindinput="getInput" />
<button style="border:2rpx solid yellow" bindtap="saveInput">存入</button>
</view>1234567891012345678910
index的js:
//index.js
//獲取應用實例
var app = getApp()
Page({
data: {
storage:''
},
onLoad: function () {
var that = this
//獲取輸入值
getInput:function(e){
this.setData({
storage:e.detail.value
})
},
//存儲輸入值
saveInput:function(){
wx.setStorageSync('storage', this.data.storage)
}
})
12345678910111213141516171819202122231234567891011121314151617181920212223
跳轉頁面:
<view>從存儲中得到的數據:{{storage}}</view>11
跳轉頁面的js:
var app = getApp();
var that;
Page( {
data: {
storage:''
},
onLoad: function(options) {
that = this;
//獲取存儲信息
wx.getStorage({
key: 'storage',
success: function(res){
// success
that.setData({
storage:res.data
})
}
})
}
})