Home  >  Article  >  WeChat Applet  >  WeChat Mini Program: New data management API

WeChat Mini Program: New data management API

高洛峰
高洛峰Original
2018-05-15 13:53:192312browse

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]

##failFunctionNo Callback function for interface call failurecompleteFunctionNoCallback function for end of interface call Function (executed successfully or failed)
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}

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]

keyString is 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 obtain relevant information about the current storage

OBJECT parameter description:
[tr]Parameter type required description[/tr]

successfailcomplete
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)
success return parameter description :

[tr]Parameter type description[/tr]

keyscurrentSizelimitSize
String Array In current storage All keys
Number The size of the space currently occupied, unit kb
Number Limited space size, unit kb
Sample code:

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)

Asynchronously remove the specified key from the local cache.

OBJECT parameter description:
[tr]Parameter type required description[/tr]

keysuccessfailcomplete
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)
Sample code:

wx.removeStorage({
    key: 'key',
    success: function(res) {
        console.log(res.data)
    }
}) wx.removeStorageSync(KEY)

Synchronously remove the specified key from the local cache.

Parameter description:
[tr]Parameter type required description[/tr]

key
String is the specified key in the local cache
Sample code:

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn