App.vue 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <template>
  2. <div id="app" v-cloak>
  3. <la-yout/>
  4. </div>
  5. </template>
  6. <script>
  7. import LaYout from '@/layout'
  8. export default {
  9. name: 'App',
  10. components: {
  11. LaYout
  12. },
  13. data() {
  14. return {
  15. include: []
  16. }
  17. },
  18. watch: {
  19. $route(to, from) {
  20. if (to.meta.keepAlive) {
  21. !this.include.includes(to.name) && this.include.push(to.name)
  22. }
  23. if (to.meta.parentNode && to.meta.parentNode.indexOf(from.name) > -1) {
  24. !this.include.includes(from.name) && this.include.push(from.name)
  25. } else if (
  26. from.meta.parentNode &&
  27. from.meta.parentNode.indexOf(to.name) > -1
  28. ) {
  29. // console.log()
  30. } else {
  31. if (from.meta.parentNode) {
  32. let index = this.include.indexOf(from.meta.parentNode)
  33. index !== -1 && this.include.splice(index, 1)
  34. }
  35. if (!from.meta.parentNode) {
  36. let index = this.include.indexOf(from.name)
  37. index !== -1 && this.include.splice(index, 1)
  38. }
  39. }
  40. }
  41. },
  42. mounted() {
  43. window.addEventListener('unload', this.saveState)
  44. },
  45. methods: {
  46. saveState() {
  47. sessionStorage.setItem('state', JSON.stringify(this.$store.state))
  48. }
  49. }
  50. }
  51. </script>
  52. <style lang="less">
  53. @import 'app.less';
  54. </style>