keepAlive.js 705 B

12345678910111213141516171819202122232425262728293031323334353637
  1. import { defineStore } from 'pinia'
  2. export const keepAliveStore = defineStore({
  3. id: 'keepAlive',
  4. state: () => ({
  5. keepLiveRoute: [],
  6. routeKey: null,
  7. routeShow: true
  8. }),
  9. getters: {},
  10. actions: {
  11. pushKeepLive(component) {
  12. if (!this.keepLiveRoute.includes(component)) {
  13. this.keepLiveRoute.push(component)
  14. }
  15. },
  16. removeKeepLive(component) {
  17. const index = this.keepLiveRoute.indexOf(component)
  18. if (index !== -1) {
  19. this.keepLiveRoute.splice(index, 1)
  20. }
  21. },
  22. clearKeepLive() {
  23. this.keepLiveRoute = []
  24. },
  25. setRouteKey(key) {
  26. this.routeKey = key
  27. },
  28. setRouteShow(key) {
  29. this.routeShow = key
  30. },
  31. setRouteKeyAction(key) {
  32. this.setRouteKey(key)
  33. }
  34. }
  35. })