New Minor Program version 1028: New Data Management API, wx. getStorage (OBJECT)
Asynchronously retrieves the content of a specified key from the local cache.
OBJECT parameter description:
[Tr] parameter type required description [/tr]
Key |
String |
Yes |
The specified key in the local cache. |
Success |
Function |
Yes |
Callback function called by the API, res = {content corresponding to data: key} |
Fail |
Function |
No |
Callback function for interface call failure |
Complete |
Function |
No |
The callback function after the interface call ends. (the callback function is executed if the call succeeds or fails) |
Sample code:
wx.getStorage({ key: 'key', success: function(res) { console.log(res.data) }}) wx.getStorageSync(KEY)
Synchronously obtains the content of the specified key from the local cache.
Parameter description:
[Tr] parameter type required description [/tr]
Key |
String |
Yes |
The specified key in the local cache. |
Sample code:
try { var value = wx.getStorageSync('key') if (value) { // Do something with return value }} catch(e) { // Do something when catch error}wx.getStorageInfo(OBJECT)
Asynchronously obtains information about the current storage.
OBJECT parameter description:
[Tr] parameter type required description [/tr]
Success |
Function |
Yes |
The callback function called by the API. for details, refer to the return parameter description. |
Fail |
Function |
No |
Callback function for interface call failure |
Complete |
Function |
No |
The callback function after the interface call ends. (the callback function is executed if the call succeeds or fails) |
Success return parameters:
[Tr] parameter type description [/tr]
Keys |
String Array |
All keys in the current storage |
CurrentSize |
Number |
Size of the space currently occupied, in kb |
LimitSize |
Number |
The size of the restricted space, in kb. |
Sample code:
Wx. getStorageInfo ({success: function (res) {console. log (res. keys); console. log (res. currentSize); console. log (res. limitSize) ;}}) ### wx. getStorageInfoSync synchronously obtains information about the current storage. ** sample code: ** "javascripttry {var res = wx. getStorageInfoSync (); console. log (res. keys); console. log (res. currentSize); console. log (res. limitSize);} catch (e) {// Do something when catch error} wx. removeStorage (OBJECT)
Asynchronously removes the specified key from the local cache.
OBJECT parameter description:
[Tr] parameter type required description [/tr]
Key |
String |
Yes |
The specified key in the local cache. |
Success |
Function |
Yes |
Callback function called by the API |
Fail |
Function |
No |
Callback function for interface call failure |
Complete |
Function |
No |
The callback function after the interface call ends. (the callback function is executed if the call succeeds or fails) |
Sample code:
wx.removeStorage({ key: 'key', success: function(res) { console.log(res.data) }}) wx.removeStorageSync(KEY)
Synchronously remove a specified key from the local cache.
Parameter description:
[Tr] parameter type required description [/tr]
Key |
String |
Yes |
The specified key in the local cache. |
Sample code:
try { wx.removeStorageSync('key')} catch(e) { // Do something when catch error}
More small programs: Add Data Management API related articles. please follow the PHP Chinese network!