?import?Vue?from?"vue";
import?axios?from?"axios";
import?VueAxios?from?"vue-axios";
import?{?XHD_BASE_URL?}?from?"./constent.js";//?域名
import?qs?from?'qs'
axios.defaults.timeout?=?10000;
//?axios.defaults.headers.post["Content-Type"]?=?"application/json";
axios.defaults.baseURL?= BASE_URL;
//?請求攔截器
axios.interceptors.request.use(
??function?(config)?{
????//?config.data=qs.stringify(config.data)
????//?console.log("axios.interceptors?request",?config);
????return?config;
??},
??function?(error)?{
????//?console.log("axios.interceptors?request?error",?error);
????return?Promise.reject(error);
??}
);
//響應(yīng)攔截器
axios.interceptors.response.use(
??function?(response)?{
????//??console.log("axios.interceptors?response",?response);
????return?response;
??},
??function?(error)?{
????//?console.log("axios.interceptors?response?error",?error,?error.message);
????if?(error.message?===?"Network?Error")?{
??????return?Promise.reject("無法連接服務(wù)器,請檢查您的網(wǎng)絡(luò)連接");
????}?else?if?(error.message.indexOf("timeout?of")?>?-1)?{
??????return?Promise.reject("客戶端請求超時");
????}?else?{
??????return?Promise.reject("未收到響應(yīng)");
????}
??}
);
Vue.use(VueAxios,?axios);
export?default?axios;