App.vue 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <template>
  2. <div id="app">
  3. <keep-alive>
  4. <router-view v-if="isRouterAlive && $route.meta.keepAlive" />
  5. </keep-alive>
  6. <router-view v-if="isRouterAlive && !$route.meta.keepAlive" />
  7. </div>
  8. </template>
  9. <script>
  10. import { on, off } from "view-design/src/utils/dom";
  11. import { setMatchMedia } from "view-design/src/utils/assist";
  12. import { mapMutations } from "vuex";
  13. setMatchMedia();
  14. export default {
  15. name: "app",
  16. provide (){
  17. return {
  18. reload:this.reload
  19. }
  20. },
  21. data(){
  22. return {
  23. isRouterAlive: true
  24. }
  25. },
  26. methods: {
  27. ...mapMutations("admin/layout", ["setDevice"]),
  28. handleWindowResize() {
  29. this.handleMatchMedia();
  30. },
  31. handleMatchMedia() {
  32. const matchMedia = window.matchMedia;
  33. if (matchMedia("(max-width: 600px)").matches) {
  34. var deviceWidth =
  35. document.documentElement.clientWidth || window.innerWidth;
  36. let css = "calc(100vw/7.5)";
  37. document.documentElement.style.fontSize = css;
  38. this.setDevice("Mobile");
  39. } else if (matchMedia("(max-width: 992px)").matches) {
  40. document.documentElement.style.fontSize = "12px";
  41. this.setDevice("Tablet");
  42. } else {
  43. document.documentElement.style.fontSize = "12px";
  44. this.setDevice("Desktop");
  45. }
  46. },
  47. reload(){
  48. this.isRouterAlive = false
  49. this.$nextTick(function () {
  50. this.isRouterAlive = true
  51. })
  52. }
  53. },
  54. mounted() {
  55. on(window, "resize", this.handleWindowResize);
  56. this.handleMatchMedia();
  57. },
  58. beforeDestroy() {
  59. off(window, "resize", this.handleWindowResize);
  60. },
  61. };
  62. </script>
  63. <style lang="less">
  64. .size {
  65. width: 100%;
  66. height: 100%;
  67. }
  68. html,
  69. body {
  70. .size;
  71. // overflow: hidden;
  72. margin: 0;
  73. padding: 0;
  74. }
  75. #app {
  76. .size;
  77. }
  78. </style>