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.

44 lines
854 B

  1. import { defineStore } from 'pinia'
  2. import { ref } from 'vue'
  3. // 定义 Store
  4. export const useDeviceStore = defineStore(
  5. 'device',
  6. () => {
  7. // 会员信息
  8. const deviceInfo = ref()
  9. // 保存会员信息,登录时使用
  10. const setDeviceInfo = (val) => {
  11. deviceInfo.value = val
  12. }
  13. // 清理会员信息,退出时使用
  14. const clearDeviceInfo = () => {
  15. deviceInfo.value = undefined
  16. }
  17. // 记得 return
  18. return {
  19. deviceInfo,
  20. setDeviceInfo,
  21. clearDeviceInfo,
  22. }
  23. },
  24. // TODO: 持久化
  25. {
  26. // 网页端持久化
  27. // persist: true,
  28. // 小程序端持久化
  29. persist: {
  30. storage: {
  31. getItem(key) {
  32. return uni.getStorageSync(key)
  33. },
  34. setItem(key, value) {
  35. uni.setStorageSync(key, value)
  36. },
  37. },
  38. },
  39. },
  40. )