This API is used via wx.setStorage(Object object).
Attribute | Type | Default value | Required | Description |
key | string | - | Yes | Specified key in the local cache |
data | any | - | Yes | The content that needs to be stored. Only native types, Date, and objects that can be serialized through JSON.stringify are supported. |
success | function | - | No | Callback Function of Successful Interface Call |
fail | function | - | No | Callback Function of Failing Interface Call |
complete | function | - | No | Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations) |
wx.setStorage({key:"key",data:"value"})
wx.setStorage({key: 'key',success (res) {console.log(res.data)}})
This API is used via wx.setStorageSync(string key, any data).
JSON.stringify
.try {wx.setStorageSync('key', 'value')} catch (e) { }
This API is used via wx.revokeBufferURL(string url)
This API is used via wx.removeStorage(Object object).
Attribute | Type | Default value | Required | Description |
key | string | - | Yes | Specified key in the local cache |
success | function | - | No | Callback Function of Successful Interface Call |
fail | function | - | No | Callback Function of Failing Interface Call |
complete | function | - | No | Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations) |
wx.removeStorage({key: 'key',success (res) {console.log(res)}})
try {wx.removeStorageSync('key')} catch(e) {// Do something when catch error}
This API is used via 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 used via wx.getStorage(Object object).
Attribute | Type | Default value | Required | Description |
key | string | - | Yes | Specified key in the local cache |
success | function | - | No | Callback Function of Successful Interface Call |
fail | function | - | No | Callback Function of Failing Interface Call |
complete | function | - | No | Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations) |
Attribute | 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 used via string wx.createBufferURL(ArrayBuffer|TypedArray buffer)
This API is used via 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 used via wx.getStorageInfo(Object object).
Attribute | Type | Default value | Required | Description |
success | function | - | No | Callback Function of Successful Interface Call |
fail | function | - | No | Callback Function of Failing Interface Call |
complete | function | - | No | Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations) |
Attribute | Type | Description |
keys | Array.<string> | All keys in the current storage. |
currentSize | number | Current occupied space size, in kilobytes (KB). |
limitSize | number | Restricted space size, in kilobytes (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 used via Object wx.getStorageInfoSync().
Attribute | Type | Description |
keys | Array. | All keys in the current storage. |
currentSize | number | Current occupied space size, in kilobytes (KB). |
limitSize | number | Restricted space size, in kilobytes (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 used via wx.clearStorage(Object object).
Attribute | Type | Default value | Required | Description |
success | function | - | No | Callback Function of Successful Interface Call |
fail | function | - | No | Callback Function of Failing Interface Call |
complete | function | - | No | Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations) |
wx.clearStorage()
try {wx.clearStorageSync()} catch(e) {// Do something when catch error}
This API is used via wx.clearStorageSync().
wx.clearStorage()
try {wx.clearStorageSync()} catch(e) {// Do something when catch error}
This API is used via wx.batchSetStorage(Object object).
Attribute | Type | Default value | Required | Description |
kvList | Array | - | Yes | [{ key, value }] |
success | function | - | No | Callback Function of Successful Interface Call |
fail | function | - | No | Callback Function of Failing Interface Call |
complete | function | - | No | Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations) |
Attribute | Type | Default value | Required | Description |
key | string | - | Yes | key The key specified in the local cache. |
value | any | - | Yes | data The content to be stored. Only native types, dates, and objects that can be serialized with JSON.stringify are supported. |
wx.setStorage({key:"key",data:"value"})
// Enable encrypted storagewx.batchSetStorage({kvList: [{key: 'key',value: 'value',}],})
This API is used via Array.<any> wx.batchGetStorageSync(Array.<string> keyList).
Attribute | Type | Default value | Required | Description |
key | string | - | Yes | Key: Specified key in the local cache. |
value | any | - | Yes | The content that needs to be stored. Only native types, Date, and objects that can be serialized through JSON.stringify are supported. |
try {wx.batchSetStorageSync([{key: 'key', value: 'value'}])} catch (e) { }
This API is used via wx.batchGetStorage(Object object).
Attribute | Type | Default value | Required | Description |
keyList | Array.<string> | - | Yes | Specified keyList in the local cache |
success | function | - | No | Callback Function of Successful Interface Call |
fail | function | - | No | Callback Function of Failing Interface Call |
complete | function | - | No | Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations) |
wx.batchGetStorage({keyList: ['key'],success (res) {console.log(res)}})
This API is used via Array.<any> wx.batchGetStorageSync(Array.<string> keyList).
// For reading multiple keys, batch reading is superior in performance to multiple getStorageSync readings.try {var valueList = wx.batchGetStorageSync(['key'])if (valueList) {// Do something with return value}} catch (e) {// Do something when catch error}
Was this page helpful?