menuStatus.ts 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // //引入pinia
  2. // import { defineStore } from 'pinia'
  3. // export const menuStatusStore = defineStore(
  4. // 'menuStatus',
  5. // {
  6. // //状态数据
  7. // state: () => ({
  8. // activeIndex: '1'
  9. // }),
  10. // //计算属性不能传参
  11. // getters: {
  12. // },
  13. // //action --相当于methods
  14. // actions: {
  15. // //对数据进行操作
  16. // saveActive(val: string) {
  17. // this.activeIndex = val
  18. // }
  19. // },
  20. // persist: {
  21. // key: 'piniaStore',
  22. // storage: sessionStorage,
  23. // paths: ['activeIndex']
  24. // }
  25. // }
  26. // )
  27. //引入pinia
  28. import { defineStore } from 'pinia'
  29. import { ref } from 'vue'
  30. export const menuStatusStore = defineStore(
  31. 'menuStatus', () => {
  32. const activeIndex = ref('1')
  33. const saveActiveIndex = (val: string) => {
  34. activeIndex.value = val
  35. }
  36. return { activeIndex, saveActiveIndex }
  37. },
  38. // { persist: true }
  39. {
  40. persist: true
  41. }
  42. )