// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import store from "./store"
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'


// 设置反向代理，前端请求默认发送到 http://localhost:8443
const axios = require('axios');
axios.defaults.baseURL = 'http://localhost:8443'
// 全局注册，之后可在其他组件中通过 this.$axios 发送数据
Vue.prototype.$axios = axios
Vue.config.productionTip = false

Vue.use(ElementUI)


router.beforeEach((to, from, next) => {
    if (to.meta.requireAuth) {
      console.log(store.state.user.username)
      if (store.state.user.username !== "") {
        console.log("success")
        next()
      } else {
        console.log("fail")
        next({
          path: '/login',
          query: {redirect: to.fullPath}
        })
      }
    } else {
      next()
    }
  }
)

store.state.user.username = ""

/* eslint-disable no-new */
new Vue({
  el: '#app',
  render: h => h(App),
  router,
  store,
  components: { App },
  template: '<App/>',
})


