forked from wangziqi/gongxue-base
20 lines
436 B
TypeScript
20 lines
436 B
TypeScript
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);
|
|
}
|