| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- /**
- * 本地存储方法封装
- */
- export const Local = {
- set(key: string, val: any) {
- uni.setStorageSync(key, val);
- },
- get(key: string) {
- return uni.getStorageSync(key);
- },
- remove(key: string) {
- uni.removeStorageSync(key);
- },
- clear() {
- uni.clearStorageSync();
- }
- };
- export const Session = {
- set(key: string, val: any) {
- // #ifdef H5
- window.sessionStorage.setItem(key, JSON.stringify(val));
- // #endif
- // #ifndef H5
- uni.setStorageSync(key, val);
- // #endif
- },
- get(key: string) {
- // #ifdef H5
- const json = window.sessionStorage.getItem(key);
- if (!json) return null;
- try {
- return JSON.parse(json);
- } catch (e) {
- return json;
- }
- // #endif
- // #ifndef H5
- return uni.getStorageSync(key);
- // #endif
- },
- remove(key: string) {
- // #ifdef H5
- window.sessionStorage.removeItem(key);
- // #endif
- // #ifndef H5
- uni.removeStorageSync(key);
- // #endif
- },
- clear() {
- // #ifdef H5
- window.sessionStorage.clear();
- // #endif
- }
- };
|