效果图展示:
我们在index页面存入数字11然后在跳转到新页面在将缓存中的11取出渲染到当前页面。具体代码如下:
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) } })跳转页面:
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 }) } }) } })