| 123456789101112131415161718192021222324252627282930313233343536373839404142 |
- // 同步取
- function getItem(key: string) {
- try {
- const value = uni.getStorageSync(key);
- if (value) {
- return value;
- }
- return null;
- } catch (e) {
- // error
- return null;
- }
- }
- // 同步存
- function setItem(key: string, data: string | boolean | number | Object) {
- uni.setStorageSync(key, data);
- }
- // 同步销毁
- function removeItem(key: string) {
- try {
- uni.removeStorageSync(key);
- } catch (e) {
- console.log('移除数据出错', e);
- }
- }
- // 同步清理所有
- function removeAll() {
- try {
- uni.clearStorageSync();
- } catch (e) {
- console.log('移除数据出错', e);
- }
- }
- export const useUniStore = () => {
- return {
- getItem,
- setItem,
- removeItem,
- removeAll
- }
- }
|