WeChat applet: New Data Management API

Source: Internet
Author: User
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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.