App.vue 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <template>
  2. <div id="app">
  3. <router-view/>
  4. </div>
  5. </template>
  6. <script>
  7. import { on, off } from 'view-design/src/utils/dom';
  8. import { setMatchMedia } from 'view-design/src/utils/assist';
  9. import { mapMutations } from 'vuex';
  10. setMatchMedia();
  11. export default {
  12. name: 'app',
  13. methods: {
  14. ...mapMutations('system/layout', [
  15. 'setDevice'
  16. ]),
  17. handleWindowResize () {
  18. this.handleMatchMedia();
  19. },
  20. handleMatchMedia () {
  21. const matchMedia = window.matchMedia;
  22. if (matchMedia('(max-width: 600px)').matches) {
  23. this.setDevice('Mobile');
  24. } else if (matchMedia('(max-width: 992px)').matches) {
  25. this.setDevice('Tablet');
  26. } else {
  27. this.setDevice('Desktop');
  28. }
  29. }
  30. },
  31. mounted () {
  32. on(window, 'resize', this.handleWindowResize);
  33. this.handleMatchMedia();
  34. },
  35. beforeDestroy () {
  36. off(window, 'resize', this.handleWindowResize);
  37. }
  38. }
  39. </script>