import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'

Vue.use(ElementUI, { size: 'small', zIndex: 3000 })

Vue.config.productionTip = false

// 路由守卫
router.beforeEach((to, from, next) => {
  NProgress.start()
  const token = store.getters['auth/token']
  if (to.meta.requiresAuth && !token) {
    next('/login')
  } else {
    next()
  }
})
router.afterEach(() => NProgress.done())

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