scrollBehavior.js 633 B

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