setStorage(params: Object)

版本要求:
BaseKit≥2.0.1@ray-js/ray≥0.3.23
支持平台:
iOSAndroid
import { setStorage } from '@ray-js/ray';

// Promise 调用
try {
  const res = await setStorage({ ...params });
  console.log(res);
} catch (err) {
  console.log(err.errorMsg);
}

描述

将数据存储在本地缓存中指定的 key 中。会覆盖掉原来该 key 对应的内容。除非用户主动删除或因存储空间原因被系统清理,否则数据都一直可用。单个 key 允许存储的最大数据长度为 1MB,所有数据存储上限为 10MB。

参数

属性类型必填说明
keystring是本地缓存中指定的 key
datastring是key对应的内容
complete() => void否接口调用结束的回调函数(调用成功、失败都会执行)
success() => void否接口调用成功的回调函数
fail(params: Object) => void否接口调用失败的回调函数
fail 回调参数
属性类型说明
errorMsgstring错误信息
errorCodestring | number错误码
错误扩展

返回值

无

示例代码

import { setStorage } from '@ray-js/ray'

// 将数据写入本地缓存指定 key(覆盖原内容)
setStorage({
  key: "demoKey",
  data: "demoValue",
  success: () => console.log("已写入"),
  fail: error => console.error(error),
});