import Vue from 'vue'
import router from './router'
import axios from 'axios'

//全局进度条
import NProgress from "nprogress";
import "nprogress/nprogress.css";

Vue.prototype.$http = axios

const http = axios.create({
    // baseURL: process.env.VUE_APP_API_URL || '/admin/api',
    baseURL: "http://localhost:8080/api"
  })

//在request拦截器中展示进度条
axios.interceptors.request.use(res =>{
    // NProgress.start()
});
//在response拦截器中隐藏进度条
axios.interceptors.response.use(res => {
  return res
}, err => {
    this.$notify.error({
        title: error
    });
    if (err.response.status === 401) {
      router.push('/login')
    }
  return Promise.reject(err)
})


export default http;