You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839
  1. //*******************************************************//
  2. // 存储数据
  3. //*******************************************************//
  4. export enum StorageKeys {
  5. Token = "token", //登录token
  6. OpenId = "openId", //openId
  7. Key = "key"//字典key
  8. }
  9. //存储
  10. export const setItem = (key : string, data : any) => {
  11. if (typeof data === "object") {
  12. data = JSON.stringify(data);
  13. }
  14. uni.setStorageSync(key, data);
  15. }
  16. //获取
  17. export const getItem = (key : string) => {
  18. const data = uni.getStorageSync(key);
  19. try {
  20. return JSON.parse(data);
  21. } catch (error) {
  22. console.log('输出内容',error)
  23. return data;
  24. }
  25. }
  26. //移除
  27. export const removeItem = (key) => {
  28. uni.removeStorageSync(key);
  29. };
  30. //清空存储
  31. export const cleanStorage = () => {
  32. uni.clearStorageSync();
  33. };