main.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import Vue from 'vue'
  2. import VueMeta from 'vue-meta'
  3. import App from './App.vue'
  4. import router from './router'
  5. import store from './store'
  6. Vue.use(VueMeta, {
  7. refreshOnceOnNavigation: true
  8. })
  9. // 移动端适配 - flexible
  10. import 'lib-flexible'
  11. // Vant UI组件(按需引入在具体组件中)
  12. import './plugins/vant'
  13. // 全局样式
  14. import './assets/styles/index.scss'
  15. // 动画库
  16. import 'animate.css'
  17. // axios
  18. import request, {
  19. baseUrl
  20. } from './utils/request'
  21. Vue.prototype.$axios = request
  22. Vue.prototype.$baseUrl = baseUrl
  23. // 全局配置
  24. Vue.config.productionTip = false
  25. // 全局方法
  26. Vue.prototype.$scrollToTop = function() {
  27. window.scrollTo({
  28. top: 0,
  29. behavior: 'smooth'
  30. })
  31. }
  32. // 防抖函数
  33. Vue.prototype.$debounce = function(fn, delay = 300) {
  34. let timer = null
  35. return function(...args) {
  36. if (timer) clearTimeout(timer)
  37. timer = setTimeout(() => {
  38. fn.apply(this, args)
  39. }, delay)
  40. }
  41. }
  42. // 节流函数
  43. Vue.prototype.$throttle = function(fn, delay = 300) {
  44. let lastTime = 0
  45. return function(...args) {
  46. const now = Date.now()
  47. if (now - lastTime > delay) {
  48. fn.apply(this, args)
  49. lastTime = now
  50. }
  51. }
  52. }
  53. import {
  54. Locale
  55. } from 'vant-green';
  56. import zhCN from 'vant-green/lib/locale/lang/zh-CN';
  57. Locale.use('zh-CN', zhCN);
  58. new Vue({
  59. router,
  60. store,
  61. render: h => h(App)
  62. }).$mount('#app')