1.wx store data to a local number and a local acquisition
Is saved to a local store to your phone, Lennon understand cutting?
wx.setStorageSync与wx.setStorage
1.1 wx.setStorageSync(string key, any data)(同步)
parameter
string key: the local cache specified key
any data: the need of content storage. Only supports native type, Date, and through JSON.stringify
the serialized object.
Sample Code
wx.setStorage({
key: 'key',
data: 'value'
})
try {
wx.setStorageSync('key', 'value')
} catch (e) { }
1.2 wx.setStorage (Object object) (asynchronous)
The data stored in the specified key in the local cache. It will overwrite the original key corresponding to the content. Data storage lifecycle consistent with the applet itself, that is over a certain time to clean up in addition to the user is automatically deleted or actively, otherwise the data have been available. The maximum allowed data stored in the individual key length of 1MB, all data stored in an upper limit of 10MB.
parameter
Object object
Attributes | Types of | Defaults | Mandatory | Explanation |
---|---|---|---|---|
key | string | Yes | Local cache specified key | |
data | any | Yes | Need of content storage. Only supports native type, Date, and through JSON.stringify the serialized object. |
|
success | function | no | Interface call success callback function | |
fail | function | no | Interface calls the failure callback function | |
complete | function | no | Interface calls the end of the callback function (call succeeds, the failure will be executed) |
Sample Code
wx.setStorage({
key: 'key',
data: 'value'
})
try {
wx.setStorageSync('key', 'value')
} catch (e) { }
The above two is a is a synchronous or asynchronous, or differentiated, to see which one would like to use to set your business
wx.getStorage与any wx.getStorageSync
1.3wx.getStorageSync (string key) (synchronous)
parameter
string key: the local cache specified key
Return Value: the any Data, Key content corresponding
Sample Code
wx.getStorage({
key: 'key',
success(res) {
console.log(res.data)
}
})
try {
const value = wx.getStorageSync('key')
if (value) {
// Do something with return value
}
} catch (e) {
// Do something when catch error
}
1.4wx.getStorage (Object object) (asynchronous)
Asynchronous Gets contents of the specified key from the local cache
Parameters: Object Object
Attributes | Types of | Defaults | Mandatory | Explanation |
---|---|---|---|---|
key | string | Yes | Local cache specified key | |
success | function | no | Interface call success callback function | |
fail | function | no | Interface calls the failure callback function | |
complete | function | no | Interface calls the end of the callback function (call succeeds, the failure will be executed) |
object.success callback function
parameter
Object res
Attributes | Types of | Explanation |
---|---|---|
data | any | key corresponding to the content |
Sample Code
wx.getStorage({
key: 'key',
success(res) {
console.log(res.data)
}
})
try {
const value = wx.getStorageSync('key')
if (value) {
// Do something with return value
}
} catch (e) {
// Do something when catch error
}