main.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import Vue from 'vue'
  2. import App from './App.vue'
  3. import router from './router'
  4. import vueEsign from 'vue-esign'
  5. import './assets/css/reset.css'
  6. import './assets/css/common.css'
  7. import './components/icon/index'
  8. import Loading from './components/loading'
  9. import toast from './components/toast'
  10. import './JS/plugin'
  11. import './JS/FastClick'
  12. import 'vant/lib/index.css'
  13. import filters from './JS/filter'
  14. import utils from './JS/utils'
  15. import VueScroller from 'vue-scroller'
  16. import { get, post, http } from './JS/ajax'
  17. import './vant'
  18. import vConsole from './JS/vconsole'
  19. Vue.use(VueScroller)
  20. Vue.use(utils)
  21. Vue.use(vueEsign)
  22. Vue.prototype.$loading = Loading
  23. Vue.prototype.$toast = toast
  24. Vue.prototype.$http = { get, post, http }
  25. // 注入全局过滤器
  26. Object.keys(filters).forEach(item => {
  27. Vue.filter(item, filters[item])
  28. })
  29. function initRem () {
  30. const cale = window.screen.availWidth > 750 ? 2 : window.screen.availWidth / 375
  31. window.document.documentElement.style.fontSize = `${100 * cale}px`
  32. }
  33. window.addEventListener('resize', function () {
  34. initRem()
  35. })
  36. Vue.config.productionTip = false
  37. router.beforeEach((to, from, next) => {
  38. document.title = to.meta.title
  39. const userInfo = localStorage.getItem('token') || null
  40. if (!userInfo && to.meta.auth) {
  41. next('/')
  42. } else {
  43. next()
  44. }
  45. })
  46. export default new Vue({
  47. el: '#app',
  48. router,
  49. render: h => h(App)
  50. })