import Vue from 'vue'
import App from './App.vue'
import router from './router/router';
import store from './store/store';
import ElementUI from 'element-ui';
import request from './request/request';
// import filters from './assets/js/filters';
import 'element-ui/lib/theme-chalk/index.css';

Vue.config.productionTip = false
Vue.prototype.request = request;
Vue.prototype.httpGet = request.get;
Vue.prototype.httpPost = request.post;
Vue.prototype.httpUploadImg = request.upPic;
Vue.use(ElementUI);

router.beforeEach((to, from, next) => {
  const token = store.getters.token;
  if (true) {
      next();
  } else {
      // 这就是跳出循环的关键(起码执行两遍)
      if (to.path === '/login') {
          next();
      }
      // 没有token跳路由，统统送去login
      else {
          next('/login');
      }
  }
});

// 注册全局过滤器
// Object.keys(filters).forEach(key => Vue.filter(key, filters[key]));

new Vue({
  router,
  store,
  render: h => h(App),
}).$mount('#app')