import axios from 'axios';import router from '@/router';import {
setSessionStorage, getSessionStorage, removeSessionStorage} from '@/utils/mixin';class Http {
constructor(){
this.Domain = 'http://*******'; }
require(options) {
if (!options.api) throw new Error('api 不能为空'); if (!options.param) { options.param = {} };
if (!options.methods) { options.methods = 'POST' }; //不传递⽅法默认为POST };
return new Promise((resolve,reject) => { let obj={
method: options.methods, url: options.api, baseURL: '/wap', headers: {
'appname':'com.immortal.jeeqin', 'platform':'web', 'v':'1.0',
'lang':'zh-CN', 'country':'CN',
'token':getSessionStorage('token') || '' },
params: options.param,//使⽤get⽅法时参数必须使⽤params data:options.param }
if(options.methods==='GET'){//判断⽅法是get时候 参数使⽤params delete obj.data }else{
delete obj.params }
return axios(obj).then(response => { const {state} = response.data; //响应数据拦截处理 if (state == 2) {
//登录超时或互踢导致登录异常,跳转⾄登录页⾯ removeSessionStorage('token'); window.location.hash = '#/login'; } else {
//请求成功
return resolve(response.data); }
},error => {
return reject() } }) }
export default Http;
因篇幅问题不能全部显示,请点此查看更多更全内容