Home > Article > WeChat Applet > WeChat Mini Program: New data management API
wx.getStorage(OBJECT)
Asynchronously obtain the content corresponding to the specified key from the local cache.
OBJECT parameter description:
[tr]Parameter type required description[/tr]
key | String | is the specified key in the | local cache |
success | Function | It is the callback function called by the | interface, res = {data: the content corresponding to key} |
Function | No | Callback function for interface call failure | |
Function | No | Callback function for end of interface call Function (executed successfully or failed) |
Sample code:
wx.getStorage({ key: 'key', success: function(res) { console.log(res.data) } }) wx.getStorageSync(KEY)Synchronously obtain the specified specification from the local cache The content corresponding to key.
Parameter description: [tr]Parameter type required description[/tr]
String | is the specified key in the | local cache |
try { var value = wx.getStorageSync('key') if (value) { // Do something with return value } } catch(e) { // Do something when catch error } wx.getStorageInfo(OBJECT)
OBJECT parameter description:
[tr]Parameter type required description[/tr]
Function | is the callback function called by the | interface. For details, please see the return parameter description | |
Function | No | Callback function for failed interface call | |
Function | No | The callback function at the end of the interface call (will be executed if the call is successful or failed) |
[tr]Parameter type description[/tr]
String Array | In current storage All keys | |
Number | The size of the space currently occupied, unit kb | |
Number | Limited space size, unit kb |
wx.getStorageInfo({
success: function(res) {
console.log(res.keys);
console.log(res.currentSize);
console.log(res.limitSize);
}
})###wx.getStorageInfoSync同步获取当前storage的相关信息 * *示例代码: * *"javascript
try {
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)
OBJECT parameter description:
[tr]Parameter type required description[/tr]
String | is the specified key in the | local cache | |
Function | Yes | The callback function called by the interface | |
Function | No | The callback function called by the interface fails Function | |
Function | No | The callback function at the end of the interface call (will be executed if the call is successful or failed) |
wx.removeStorage({ key: 'key', success: function(res) { console.log(res.data) } }) wx.removeStorageSync(KEY)
Parameter description:
[tr]Parameter type required description[/tr]
String | is the specified key in the | local cache |
try {
wx.removeStorageSync('key')
} catch(e) {
// Do something when catch error
}
For more WeChat mini programs: New data management API, please pay attention to the PHP Chinese website for related articles!