main.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 { VueJsonp } from 'vue-jsonp'
  5. Vue.use(VueJsonp)
  6. import App from './App'
  7. import router from './router'
  8. import store from './store/store' // 引入store
  9. import resource from 'vue-resource' // 引入vue-resource
  10. import tabbar from './components/tabbar.vue'
  11. import banner from './components/banner.vue'
  12. import back from './components/back.vue'
  13. import backIndex from './components/backindex.vue'
  14. import Vant from 'vant'
  15. import clipboard from 'clipboard'
  16. import 'vant/lib/index.css'
  17. import wx from 'weixin-js-sdk'
  18. Vue.prototype.$wx = wx
  19. Vue.component('tabbar', tabbar)
  20. Vue.component('banner', banner)
  21. Vue.component('back', back)
  22. Vue.component('backindex', backIndex)
  23. Vue.config.productionTip = false
  24. Vue.use(Vant)
  25. Vue.use(resource)
  26. import common from './script/common.js'
  27. Vue.use(common)
  28. Vue.prototype.clipboard = clipboard
  29. // 时间戳过滤器
  30. Vue.filter('dateFormat', (dataStr) => {
  31. var time = new Date(dataStr)
  32. function timeAdd0(str) {
  33. if (str < 10) {
  34. str = '0' + str
  35. }
  36. return str
  37. }
  38. var y = time.getFullYear()
  39. var m = time.getMonth() + 1
  40. var d = time.getDate()
  41. var h = time.getHours()
  42. var mm = time.getMinutes()
  43. var s = time.getSeconds()
  44. return y + '-' + timeAdd0(m) + '-' + timeAdd0(d) + ' ' + timeAdd0(h) + ':' + timeAdd0(mm) + ':' + timeAdd0(s)
  45. })
  46. // Vue.prototype.common=common
  47. // Vue.http.options.emulateJSON = true;
  48. // Vue.http.options.headers = {'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'};
  49. // Vue.http.interceptors.push((request, next) => {
  50. // next((response) => {}
  51. // })
  52. /* eslint-disable no-new */
  53. router.beforeEach((to, from, next) => {
  54. if (to.matched.some(record => record.meta.needLogin)) { // 判断该路由是否需要登录权限
  55. // 登录判断
  56. if (localStorage.getItem('userId')) { // 判断当前用户的登录信息loginInfo是否存在
  57. next()
  58. } else {
  59. next({
  60. path: '/Login'
  61. })
  62. }
  63. } else {
  64. next()
  65. }
  66. })
  67. new Vue({
  68. el: '#app',
  69. router,
  70. store: store,
  71. components: { App },
  72. template: '<App/>'
  73. })