transformResponse: [functiontransformResponse(data) { /*eslint no-param-reassign:0*/ if (typeof data === 'string') { try { data = JSON.parse(data); } catch (e) { /* Ignore */ } } return data; }],
/** * A timeout in milliseconds to abort a request. If set to 0 (default) a * timeout is not created. */ timeout: 0, //超时时间设置 // 防止CSRF攻击字段 xsrfCookieName: 'XSRF-TOKEN', xsrfHeaderName: 'X-XSRF-TOKEN',
maxContentLength: -1,
validateStatus: functionvalidateStatus(status) { return status >= 200 && status < 300; } };
/** * Accepts varargs expecting each argument to be an object, then * immutably merges the properties of each object and returns result. * * When multiple objects contain the same key the later object in * the arguments list will take precedence. * * Example: * * ```js * var result = merge({foo: 123}, {foo: 456}); * console.log(result.foo); // outputs 456 * ``` * * @param {Object} obj1 Object to merge * @returns {Object} Result of all merge properties */ // 这里主要就是将多个对象的属性合并到一个对象中,相同的属性,后面出现的值会覆盖前面的值 // 比如官方例子中 merge({foo:123}, {foo:456}) 将返回 {foo: 456} // merge({foo:132}, {hhh:456}), 将返回{foo: 132, hhh: 456} functionmerge(/* obj1, obj2, obj3, ... */) { var result = {}; functionassignValue(val, key) { if (typeof result[key] === 'object' && typeof val === 'object') { result[key] = merge(result[key], val); } else { result[key] = val; } }
for (var i = 0, l = arguments.length; i < l; i++) { forEach(arguments[i], assignValue); } return result; }
/** * Extends object a by mutably adding to it the properties of object b. * * @param {Object} a The object to be extended * @param {Object} b The object to copy properties from * @param {Object} thisArg The object to bind function to * @return {Object} The resulting value of object a */ // 这个方法是用来扩展a对象的属性,将b对象上的属性和方法扩展到a上,并指定执行上下文(保证this指向) functionextend(a, b, thisArg) { forEach(b, functionassignValue(val, key) { if (thisArg && typeof val === 'function') { a[key] = bind(val, thisArg); } else { a[key] = val; } }); return a; }
/** * Dispatch a request to the server using the configured adapter. * * @param {object} config The config that is to be used for the request * @returns {Promise} The Promise to be fulfilled */ module.exports = functiondispatchRequest(config) { // 请求取消抛出错误 throwIfCancellationRequested(config);
// Support baseURL config if (config.baseURL && !isAbsoluteURL(config.url)) { config.url = combineURLs(config.baseURL, config.url); }