# setStorage
APP本地化存储存值
# 调用方式
setStorage(key, value, set_time = false, duration = 0)
1
返回 Promise,使用 then/catch 或 await 处理结果。
# 请求参数
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
| key | String | Y | — | 存储键,不能为空 |
| value | String / Object | Y | — | 存储值;对象会序列化为 JSON |
| set_time | Boolean | N | false | 是否在存储字符串末尾拼接时间戳 |
| duration | Number | N | 0 | 附加的有效时长,单位小时;仅 set_time=true 时使用 |
# 接口调用示例
this.$bridge.setStorage('example-key', { value: 1 })
.then(res => {
console.log(res)
})
.catch(error => {
console.error(error)
})
1
2
3
4
5
6
7
2
3
4
5
6
7
# 返回参数
有效 key 返回 Promise,resolve 原生存储事件;异常时 reject。key 为空时直接返回 undefined。
# 注意事项
时间戳是附加的字符串内容;当前 getStorage 不自动根据时间戳删除或过滤数据。