import { AsyncStorage } from "react-native"; export default class DeviceStorage { static get(key) { return AsyncStorage.getItem(key).then(value => { const jsonValue = JSON.parse(value); return jsonValue; }); } static save(key, value) { return AsyncStorage.setItem(key, JSON.stringify(value)); } static update(key, value) { return DeviceStorage.get(key).then(item => { value = typeof value === "string" ? value : Object.assign({}, item, value); return AsyncStorage.setItem(key, JSON.stringify(value)); }); } static delete(key) { return AsyncStorage.removeItem(key); } } /** 使用方法: 1.先引用asyncStorage.js文件 2.调用方法 //获取 asyncStorage.get("birthday").then(birthday => { if (birthday == null || birthday == "") { consle.log("birthday is null"); } else { alert("birthday:" + birthday); } }); //存储 asyncStorage.save("birthday", this.state.birthday_time); //更新 asyncStorage.update("birthday","this.state.birthday_time"); //删除 asyncStorage.delete("birthday"); */