forked from wangziqi/gongxue-base
feat: scaffold taro h5 frontends
This commit is contained in:
19
apps/taro/src/services/storage.ts
Normal file
19
apps/taro/src/services/storage.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import Taro from '@tarojs/taro';
|
||||
|
||||
export function getStorage<T>(key: string): T | null {
|
||||
try {
|
||||
const value = Taro.getStorageSync<string>(key);
|
||||
if (!value) return null;
|
||||
return JSON.parse(value) as T;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export function setStorage<T>(key: string, value: T) {
|
||||
Taro.setStorageSync(key, JSON.stringify(value));
|
||||
}
|
||||
|
||||
export function removeStorage(key: string) {
|
||||
Taro.removeStorageSync(key);
|
||||
}
|
||||
Reference in New Issue
Block a user