// 配置api接口地址 var root = "https://www.lihero.com:8081/" // 自定义判断元素类型js function totype(obj) { return ({}).tostring.call(obj).match(/\s([a-za-z]+)/)[1].tolowercase() } // 参数过滤函数 function filternull(o) { for (var key in o) { if (o[key] === null) { delete o[key] } if (totype(o[key]) === "string") { o[key] = o[key].trim() } else if (totype(o[key]) === "object") { o[key] = filternull(o[key]) } else if (totype(o[key]) === "array") { o[key] = filternull(o[key]) } } return o } /* * 接口处理函数 * 主要是,不同的接口的成功标识和失败提示是不一致的。 */ function apiaxios(method, url, params, success, failure) { if (params) { params = filternull(params) } axios({ method: method, url: url, data: method === 'post' || method === 'put' ? params : null, params: method === 'get' || method === 'delete' ? params : null, baseurl: root + "/", withcredentials: false }) .then(function (res) { success(res.data) }) .catch(function (err) { if (failure) { failure(err) } else { if (err.response) { //跳转404 } } }) }