同步版本加Sync在storage后面
存储:
wx.setStorage({
key:"key",
data:"value"
})
wx.setStorage('storage', this.data.storage)
获取:
that = this;
wx.getStorage({
key: 'storage',
success: function(res){
// success
that.setData({
storage:res.data
})
}
})
移除:
wx.removeStorage({
key: 'storage',
success (res) {
console.log(res)
}
})
清理:
wx.clearStorage()
实例:
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)
}
})
跳转页面的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
})
}
})
}
})
来源:CSDN
作者:迷途知返9527
链接:https://blog.csdn.net/qq_40942640/article/details/104523299