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

WeChat Mini Program: New data management API

高洛峰
Release: 2018-05-15 13:53:19
Original
2330 people have browsed it

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)
Copy after login

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)
Copy after login

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
FunctionNoCallback function for failed interface call
FunctionNoThe 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 ArrayIn current storage All keys
NumberThe size of the space currently occupied, unit kb
NumberLimited 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)
Copy after login

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 YesThe callback function called by the interface
FunctionNoThe callback function called by the interface fails Function
FunctionNoThe 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)
Copy after login

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
}
Copy after login

For more WeChat mini programs: New data management API, please pay attention to the PHP Chinese website for related articles!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template