main.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. console.log('H5调用')
  31. const setHtmlFontSize = () => {
  32. const htmlDom = document.getElementsByTagName('html')[0];
  33. let htmlWidth = document.documentElement.clientWidth || document.body.clientWidth;
  34. if (htmlWidth >= 750) {
  35. htmlWidth = 750;
  36. }
  37. if (htmlWidth <= 320) {
  38. htmlWidth = 320;
  39. }
  40. htmlDom.style.fontSize = `${htmlWidth / 7.5}px`;
  41. };
  42. window.onresize = setHtmlFontSize;
  43. setHtmlFontSize();
  44. }
  45. const originalPush = router.prototype.push;
  46. router.prototype.push = function push(location) {
  47. return originalPush.call(this, location).catch(err => err)
  48. }