scrollBehavior.js 675 B

1234567891011121314151617181920212223242526272829
  1. import { nextTick } from 'vue'
  2. import { viewTagsStore } from '@/store'
  3. export function beforeEach(to, from) {
  4. const adminMain = document.querySelector('#admin-ui-main')
  5. if (!adminMain) {
  6. return false
  7. }
  8. const store = viewTagsStore()
  9. store.updateViewTags({
  10. fullPath: from.fullPath,
  11. scrollTop: adminMain.scrollTop
  12. })
  13. }
  14. export function afterEach(to) {
  15. const adminMain = document.querySelector('#admin-ui-main')
  16. if (!adminMain) {
  17. return false
  18. }
  19. nextTick(() => {
  20. const store = viewTagsStore()
  21. const beforeRoute = store.viewTags.filter((v) => v.fullPath == to.fullPath)[0]
  22. if (beforeRoute) {
  23. adminMain.scrollTop = beforeRoute.scrollTop || 0
  24. }
  25. })
  26. }