main.js 845 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. import Vue from "vue";
  2. import App from "./App.vue";
  3. import router from "./router";
  4. import store from "./store";
  5. import { getToken } from "./utils/auth";
  6. // import { Lazyload } from 'vant';
  7. Vue.config.productionTip = false;
  8. /* 图片懒加载,设置默认图片 */
  9. /* Vue.use(Lazyload,{
  10. preLoad: 1.3,
  11. error: 'dist/error.png',
  12. loading: 'dist/loading.gif',
  13. attempt: 1
  14. }) */
  15. router.beforeEach((to, from, next) => {
  16. //白名单路由
  17. const whiteUrl = ["/login", "/forget", "/register", "/signin_github","/usreMei"];
  18. if (getToken()) {
  19. if (to.path === "/login") {
  20. next("/home");
  21. } else {
  22. store.dispatch("GetUser");
  23. }
  24. next();
  25. } else {
  26. if (whiteUrl.includes(to.path)) {
  27. next();
  28. } else {
  29. next("/login");
  30. }
  31. }
  32. });
  33. new Vue({
  34. router,
  35. store,
  36. render: h => h(App)
  37. }).$mount("#app");