Page(
{
data: {
// text:"這是一個頁面"
storageContent: '',
storageSyncContent: ''
},
onLoad: function (options) { // 頁面初始化 options為頁面跳轉所帶來的參數
},
/** * 異步存儲 */
listenerStorageSave: function () {
//以鍵值對的形式存儲 傳進去的是個對象
wx.setStorage(
{
key: 'key',
data: '我是storeage異步存儲的信息',
success: function (res) {
console.log(res)
}
})
},
/** * 異步取信息 */
listenerStorageGet: function () {
var that = this; wx.getStorage({
//獲取數據的key
key: 'key',
success: function (res) {
console.log(res)
that.setData({
//
storageContent: res.data
})
},
/** * 失敗會調用 */
fail: function (res) { console.log(res) }
})
},
/** * 清除數據 */ listenerStorageClear: function () { var that = this; wx.clearStorage({ success: function (res) { that.setData({ storageContent: '' }) } }) },
/** * 數據同步存儲 */
listenerStorageSyncSave: function () { wx.setStorageSync('key', '我是同步存儲的數據') },
/** * 數據同步獲取 */
listenerStorageSyncGet: function () {
//
var that = this;
var value = wx.getStorageSync('key')
this.setData({ storageSyncContent: value })
},
/** * 清除同步存儲數據 */
listenerStorageSyncClear: function () { wx.clearStorageSync() }, onReady: function () {
// 頁面渲染完成
},
onShow: function () {
// 頁面顯示
},
onHide: function () {
// 頁面隱藏
},
onUnload: function () {
// 頁面關閉
}
})