setStorage
Lưu ý
Cần xin cấp quyền tại trang Quản lý ứng dụng
Lưu trữ dữ liệu xuống bộ đệm. Dữ liệu sẽ được lưu ở thiết bị của người dùng. Dữ liệu cũ nhất sẽ bị xoá nếu bộ nhớ đạt giới hạn.
Parameters
Object object
Property | Type | Default | Required | Description | Minimum Version |
---|---|---|---|---|---|
data | Object<Record<string, any>> | true | Dữ liệu cần lưu trữ | ||
success | function | Callback function khi gọi api thành công | |||
fail | function | Callback function khi gọi api thất bại |
Return Values
Promise <Object data>
Property | Type | Description | Minimum Version |
---|---|---|---|
errorKeys | Array<string> | Danh sách các dữ liệu lưu lỗi |
Sample Code
import { setStorage } from "zmp-sdk/apis";
setStorage({
data: {
key1: "string",
key2: {
boolean: true
},
key3: 1
},
success: (data) => {
// xử lý khi gọi api thành công
const { errorKeys } = data;
},
fail: (error) => {
// xử lý khi gọi api thất bại
console.log(error);
}
});
Hoặc
import { setStorage } from "zmp-sdk/apis";
const setDataToStorage = async () => {
try {
const { errorKeys } = await setStorage({
data: {
key1: "data1",
key2: {
key4: "data2"
},
key3: "data3"
}
});
} catch (error) {
// xử lý khi gọi api thất bại
console.log(error);
}
};