// 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 axios from "axios"; import Cube from "./index"; import Store from "./store/store"; // import http from "../src/request/http"; import "lib-flexible"; import "./filters"; console.info('v1.0.2'); Vue.use(Cube); // 设置默认请求接口(删掉地址栏中的后缀) let domainName = location.host; //域名 let protocolName = document.location.protocol; //http协议 axios.defaults.baseURL = protocolName + "//" + domainName; // axios.defaults.baseURL = http.host; // axios.defaults.timeout = 5000; axios.defaults.headers["Content-Type"] = "application/json;charset=UTF-8"; Vue.prototype.$http = axios; Vue.config.productionTip = false; // http request拦截器 添加一个请求拦截器 axios.interceptors.request.use( function(config) { document.cookie = "JSESSIONID=A835F24A945D3E045DEE5FA5C3AD40AB"; let token = window.localStorage.getItem("token"); if (token) { config.headers["access-token"] = token; //将token放到请求头发送给服务器 } return config; }, function(error) { return Promise.reject(error); } ); let count = 0; // http response 拦截器 axios.interceptors.response.use( response => { if (response.data.state == 433 && count < 1) { count++; alert(response.data.error + ",请重新登录!"); router.push({ path: "/login" }); window.location.reload(); } return response; } // error => { // if (error.response) { // alert(error.response.status) // switch (error.response.status) { // case 401: // // 401 清除token信息并跳转到登录页面 // // 只有在当前路由不是登录页面才跳转 // // router.currentRoute.path !== 'login' && // // router.replace({ // // path: '/login', // // // query: { // // // redirect: router.currentRoute.path // // // }, // // }) // router.push({ path: "/login" }); // } // } // // console.log(JSON.stringify(error));//console : Error: Request failed with status code 402 // return Promise.reject(response.data.error) // }, ); /* eslint-disable no-new */ new Vue({ el: "#app", router, components: { App }, template: "", store: Store });