小程式 微信本地儲存的方法使用

2022-03-08 15:32:46 字數 1171 閱讀 4875

需要儲存的內容。只支援原生型別、date、及能夠通過json.stringify序列化的物件。

(1)wx.setstoragesync();  //儲存值

1

try catch

(e)

(2)wx.removestoragesync();   // 移除指定的值

1

try catch

(e)

(3)wx.getstoragesync();  //

獲取值

1

try6 } catch

(e)

(4)wx.getstorageinfosync();  //

獲取當前 storage 中所有的

key

1

try catch

(e)

(5)wx.clearstoragesync();  //

清除所有的

key

1

try catch

(e)

(1)wx.setstorage();  //儲存值

將資料儲存在本地快取中指定的 key 中。會覆蓋掉原來該

key

對應的內容。資料儲存生命週期跟小程式本身一致,即除使用者主動刪除或超過一定時間被自動清理,否則資料都一直可用。單個

key

允許儲存的最大資料長度為

1mb,所有資料儲存上限為

10mb

1

wx.setstorage()

(2)wx.removestorage();   // 移除指定的值

1

wx.removestorage(})

(3)wx.getstorage();  //

獲取值

1

wx.getstorage(})

(4)wx.getstorageinfo();  //

獲取當前 storage 中所有的

key

1

wx.getstorageinfo(})

(5)wx.clearstorage();  //

清除所有的

key

1 wx.clearstorage()

小程式 微信本地儲存的方法

同步方法會堵塞當前任務,直到同步方法處理返回。非同步方法不會塞當前任務。1 同步 1 wx.setstoragesync 儲存值 try catch e 2 wx.getstoragesync 獲取值 try catch e 3 wx.removestoragesync 移除指定的值 try cat...

小程式 本地儲存

通過collected來判斷!1 var newsdata require data newsdata.js 23 page 1112 13 生命週期函式 監聽頁面載入 14 15 onload function options 21 第一次進入的適合判斷是否存在本地儲存以及是否收藏 22var n...

微信小程式本地儲存的非同步同步用法詳解

1.wx.setstoragesync 儲存值 try catch e 2.wx.getstoragesync 獲取值 try catch e 3.wx.removestoragesync 移除指定的值 try catch e 4.wx.getstorageinfosync 獲取當前 storage...