This API is called using wx.setStorage(Object object).
Property | Type | Default value | Required | Description |
key | string | - | True | The key specified in the local cache. |
data | any | - | True | The content that needs to be stored. Only objects of native types, dates, and objects that can be serialized via JSON.stringify are supported. |
success | function | - | False | Callback function for successful API calls. |
fail | function | - | False | Callback function for failed API calls. |
complete | function | - | False | Callback function executed after API call ends (regardless of success or failure). |
wx.setStorage({key:"key",data:"value"})
wx.setStorage({key: 'key',success (res) {console.log(res.data)}})
This API is called using wx.setStorageSync(string key, any data).
JSON.stringify
are supported.try {wx.setStorageSync('key', 'value')} catch (e) { }
This API is called using wx.revokeBufferURL(string url).
This API is called using wx.removeStorage(Object object).
Property | Type | Default value | Required | Description |
key | string | - | True | The key specified in the local cache. |
success | function | - | False | Callback function for successful API calls. |
fail | function | - | False | Callback function for failed API calls. |
complete | function | - | False | Callback function executed after API call ends (regardless of success or failure). |
wx.removeStorage({key: 'key',success (res) {console.log(res)}})
try {wx.removeStorageSync('key')} catch (e) {// Do something when catch error}
This API is called using wx.removeStorageSync(string key).
wx.removeStorage({key: 'key',success (res) {console.log(res)}})
try {wx.removeStorageSync('key')} catch (e) {// Do something when catch error}
This API is called using wx.getStorage(Object object).
Property | Type | Default value | Required | Description |
key | string | - | True | The key specified in the local cache. |
success | function | - | False | Callback function for successful API calls. |
fail | function | - | False | Callback function for failed API calls. |
complete | function | - | False | Callback function executed after API call ends (regardless of success or failure). |
Property | Type | Description |
data | any | The content corresponding to the key. |
wx.getStorage({key: 'key',success (res) {console.log(res.data)}})
wx.getStorage({key: 'key',success (res) {console.log(res.data)}})
This API is called using string wx.createBufferURL(ArrayBuffer|TypedArray buffer).
This API is called using any wx.getStorageSync(string key).
try {var value = wx.getStorageSync('key')if (value) {// Do something with return value}} catch (e) {// Do something when catch error}
This API is called using wx.getStorageInfo(Object object).
Property | Type | Default value | Required | Description |
success | function | - | False | Callback function for successful API calls. |
fail | function | - | False | Callback function for failed API calls. |
complete | function | - | False | Callback function executed after API call ends (regardless of success or failure). |
Property | Type | Description |
keys | Array.<string> | All keys in the current storage. |
currentSize | number | Currently used space size in KB. |
limitSize | number | Limited space size in KB. |
wx.getStorageInfo({success(res) {console.log(res.keys)console.log(res.currentSize)console.log(res.limitSize)}})
wx.getStorageInfo({success(res) {console.log(res.keys)console.log(res.currentSize)console.log(res.limitSize)}})
This API is called using Object wx.getStorageInfoSync().
Property | Type | Description |
keys | Array. | All keys in the current storage. |
currentSize | number | Currently used space size in KB. |
limitSize | number | Limited space size in KB. |
wx.getStorageInfo({success (res) {console.log(res.keys)console.log(res.currentSize)console.log(res.limitSize)}})
try {const res = wx.getStorageInfoSync()console.log(res.keys)console.log(res.currentSize)console.log(res.limitSize)} catch (e) {// Do something when catch error}
This API is called using wx.clearStorage(Object object).
Property | Type | Default value | Required | Description |
success | function | - | False | Callback function for successful API calls. |
fail | function | - | False | Callback function for failed API calls. |
complete | function | - | False | Callback function executed after API call ends (regardless of success or failure). |
wx.clearStorage()
try {wx.clearStorageSync()} catch(e) {// Do something when catch error}
This API is called using wx.clearStorageSync().
wx.clearStorage()
try {wx.clearStorageSync()} catch(e) {// Do something when catch error}
This API is called using wx.batchSetStorage(Object object).
Property | Type | Default value | Required | Description |
kvList | Array | - | True | [{ key, value }] |
success | function | - | False | Callback function for successful API calls. |
fail | function | - | False | Callback function for failed API calls. |
complete | function | - | False | Callback function executed after API call ends (regardless of success or failure). |
Property | Type | Default value | Required | Description |
key | string | | True | The key specified in the local cache. |
value | any | | True | The content that needs to be stored. Only objects of native types, dates, and objects that can be serialized via JSON.stringify are supported. |
wx.setStorage({key:"key",data:"value"})
// Enable encrypted storagewx.batchSetStorage({kvList: [{key: 'key',value: 'value',}],})
This API is called using Array.<any> wx.batchGetStorageSync(Array.<string> keyList).
Property | Type | Default value | Required | Description |
key | string | - | True | The key specified in the local cache. |
value | any | - | True | The content that needs to be stored. Only objects of native types, dates, and objects that can be serialized via JSON.stringify are supported. |
try {wx.batchSetStorageSync([{key: 'key', value: 'value'}])} catch (e) { }
This API is called using wx.batchGetStorage(Object object).
Property | Type | Default value | Required | Description |
keyList | Array.<string> | - | True | The keyList specified in the local cache. |
success | function | - | False | Callback function for successful API calls. |
fail | function | - | False | Callback function for failed API calls. |
complete | function | - | False | Callback function executed after API call ends (regardless of success or failure). |
wx.batchGetStorage({keyList: ['key'],success (res) {console.log(res)}})
This API is called using Array.<any> wx.batchGetStorageSync(Array.<string> keyList).
//Batch reading is more efficient than multiple getStorageSync calls when retrieving multiple keystry {var valueList = wx.batchGetStorageSync(['key'])if (valueList) {// Do something with return value}} catch (e) {// Do something when catch error}