main.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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 store from './store'
  7. import ElementUI from 'element-ui';
  8. import 'element-ui/lib/theme-default/index.css'
  9. import NProgress from 'nprogress'
  10. import 'normalize.css/normalize.css';// normalize.css 样式格式化
  11. import '@/styles/index.scss'; // 全局自定义的css样式
  12. import '@/components/Icon-svg/index'; // 封装的svg组件
  13. Vue.config.productionTip = false
  14. Vue.use(ElementUI);
  15. router.afterEach(() => {
  16. NProgress.done(); // 结束Progress
  17. });
  18. // const whiteList = ['/login', '/authredirect', '/reset', '/sendpwd'];// 不重定向白名单
  19. // router.beforeEach((to, from, next) => {
  20. // NProgress.start(); // 开启Progress
  21. // if (store.getters.token) { // 判断是否有token
  22. // if (to.path === '/login') {
  23. // next({ path: '/' });
  24. // } else {
  25. // if (store.getters.roles.length === 0) { // 判断当前用户是否已拉取完user_info信息
  26. // store.dispatch('GetInfo').then(res => { // 拉取user_info
  27. // const roles = res.data.role;
  28. // store.dispatch('GenerateRoutes', { roles }).then(() => { // 生成可访问的路由表
  29. // router.addRoutes(store.getters.addRouters) // 动态添加可访问路由表
  30. // next(to.path); // hack方法 确保addRoutes已完成
  31. // })
  32. // }).catch(err => {
  33. // console.log(err);
  34. // });
  35. // } else {
  36. // // 没有动态改变权限的需求可直接next() 删除下方权限判断 ↓
  37. // if (hasPermission(store.getters.roles, to.meta.role)) {
  38. // next();//
  39. // } else {
  40. // next({ path: '/401', query: { noGoBack: true } });
  41. // }
  42. // // 可删 ↑
  43. // }
  44. // }
  45. // } else {
  46. // if (whiteList.indexOf(to.path) !== -1) { // 在免登录白名单,直接进入
  47. // next()
  48. // } else {
  49. // next('/login'); // 否则全部重定向到登录页
  50. // NProgress.done(); // 在hash模式下 改变手动改变hash 重定向回来 不会触发afterEach 暂时hack方案 ps:history模式下无问题,可删除该行!
  51. // }
  52. // }
  53. // });
  54. new Vue({
  55. el: '#app',
  56. router,
  57. store,
  58. template: '<App/>',
  59. components: { App }
  60. })