main.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. // The Vue build version to load with the `import` command
  2. // (runtime-only or standalone) has been set in webpack.base.conf with an alias.
  3. import Vue from 'vue'
  4. import App from './App'
  5. import router from './router'
  6. import ElementUI from 'element-ui';
  7. import 'element-ui/lib/theme-chalk/index.css';
  8. import VueAwesomeSwiper from 'vue-awesome-swiper'
  9. import Vant from 'vant';
  10. import 'vant/lib/index.css';
  11. import {
  12. isMobile
  13. } from "@/util"
  14. Vue.use(Vant);
  15. Vue.use(ElementUI);
  16. Vue.config.productionTip = false
  17. /* eslint-disable no-new */
  18. new Vue({
  19. el: '#app',
  20. router,
  21. components: {
  22. App
  23. },
  24. template: '<App/>'
  25. })
  26. router.afterEach((to, from, next) => {
  27. window.scrollTo(0, 0)
  28. })
  29. if (isMobile()) {
  30. const setHtmlFontSize = () => {
  31. const htmlDom = document.getElementsByTagName('html')[0];
  32. let htmlWidth = document.documentElement.clientWidth || document.body.clientWidth;
  33. if (htmlWidth >= 750) {
  34. htmlWidth = 750;
  35. }
  36. if (htmlWidth <= 320) {
  37. htmlWidth = 320;
  38. }
  39. htmlDom.style.fontSize = `${htmlWidth / 7.5}px`;
  40. };
  41. window.onresize = setHtmlFontSize;
  42. setHtmlFontSize();
  43. }