const { ccclass, property } = cc._decorator; @ccclass export default class StorageMgr { //单例 private static _instance: StorageMgr = null public static get Inst() { if (this._instance == null) { this._instance = new StorageMgr() } return this._instance; } /**获取存储 * @param:key key值 */ getStorage(key: string): any { if (cc.sys.localStorage.getItem(key)) { return JSON.parse(cc.sys.localStorage.getItem(key)); } else { return null; } } /**存储 * @param: key key值 * @param: value 要存储的value值 */ setStorage(key: string, value: any) { cc.sys.localStorage.setItem(key, JSON.stringify(value)); } }