数据缓存,前端开发

数据缓存,uni-app官网文档链接。

<https://uniapp.dcloud.net.cn/api/storage/storage.html#removestorage>uni.setStorage

uni.getStorage

uni.setStorageSync

uni.getStorageSync

uni.getStorageInfo

uni.getStorageInfoSync1.uni.setStorage(object)

将数据存储在本地缓存指定的key中,会覆盖原来key对应的内容,这是一个异步接口。

uni.setStorage({

 key: 'storage_key',

 data: 'hello',

 success: function () {

  console.log('success');

 }

});key:string类型,本地存储指定的key。

data:Any类型,是存储的内容,只支持原生类型、及能够通过JSON.stringify序列化对象。

success,fail,complete是Function类型,success是在接口调用成功的回调函数,fail是接口调用失败的回调函数,complete是接口调用结束的回调函数(调用成功、失败都会执行)

2.uni.getStorage(object)

从本地缓存中异步获取指定key对应的内容。

uni.getStorage({

 key: 'storage_key',

 success: function (res) {

  console.log(res.data);

 }

});key:本地缓存中指定的key。

success返回的参数data是可以对应的内容。

3.uni.setStorageSync(key,data)

将data存储在本地缓存指定的key中,会覆盖原来key对应的内容,这是一个同步接口。

try {

 uni.setStorageSync('storage_key', 'hello');

} catch (e) {

 // error

}key:本地缓存中指定的key。

data:需要存储的内容,只支持原生类型,及能够通过JSON.stringify序列化的对象。

4.uni.getStorageSync(key)

从本地缓存中同步获取指定key

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

鲸沉于海底、不灵

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值