tt.getStorageInfoSync
基础库
1.0.0
开始支持本方法,这是一个同步方法。
同步获取当前本地缓存数据的相关信息。
语法
tt.getStorageInfoSync()
参数说明
无
返回值
返回值为 object
类型,详细参数描述如下:
名称 | 数据类型 | 描述 |
---|---|---|
keys | string[] | 本地数据缓存中的所有键名列表,如本地数据则返回空数组 |
currentSize | number | 占用空间大小,以 KB 为单位 |
limitSize | number | 存储空间上限,以 KB 为单位,一般来说会返回 10240 |
效果示例

扫码体验
请使用字节宿主APP扫码
代码示例
<!-- index.ttml -->
<button type="primary" bindtap="setStorage">setStorage</button>
<button type="primary" bindtap="getStorageInfoSync">getStorageInfoSync</button>
// index.js
Page({
setStorage() {
tt.setStorage({
key: "test_key",
data: "byteDance",
success: (res) => {
tt.showToast({ title: "存储成功" });
},
fail: (err) => {
tt.showModal({
title: "存储失败",
content: err.errMsg,
showCancel: false,
});
},
complete: (res) => console.log("存储完成"),
});
},
getStorageInfoSync() {
var res = tt.getStorageInfoSync();
tt.showModal({
title: "读取成功",
content: `当前storage所有的key:${JSON.stringify(res.keys)}`,
showCancel: false,
});
},
});
Bug & Tip
暂无
点击纠错
评价此篇文档