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.

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