main.js 961 B

123456789101112131415161718192021222324252627282930313233343536
  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 './config/config'
  7. import ajax from './common/axios.config'
  8. import { Message } from 'element-ui'
  9. Vue.config.productionTip = false
  10. import { Form } from 'element-ui'
  11. Vue.prototype.$store = store;// 将store实例挂在vue原型上
  12. Vue.prototype.ajax = ajax
  13. Vue.prototype.$message = Message
  14. /* eslint-disable no-new */
  15. new Vue({
  16. el: '#app',
  17. router,
  18. components: { App },
  19. template: '<App/>'
  20. })
  21. router.beforeEach((to, from, next) => {
  22. console.log('1');
  23. ajax
  24. .get(`${store.state.server}getcookieuserid`)
  25. .then((res) => {
  26. store.commit("update", ["userId", res.data[0][0].userid]);
  27. })
  28. .catch((err) => {
  29. window.location.href = "https://edu.cocorobo.cn/course/login?type=1";
  30. });
  31. next();
  32. })