diff --git a/package.json b/package.json index 0b31fa2..889e617 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@bytedo/fetch", - "version": "1.0.0", + "version": "1.0.1", "description": "全新的ajax封装。分2个版本, 一个基于XMLHttpRequest, 一个基于window.fetch", "main": "dist/index.js", "directories": { diff --git a/src/index.es7 b/src/index.es7 index 9c5f3e6..58d823a 100644 --- a/src/index.es7 +++ b/src/index.es7 @@ -77,11 +77,18 @@ class _Request { control.abort() } - if (__INIT__.headers && options.headers) { - Object.assign(__INIT__.headers, options.headers) + var headers = this.options.headers + + if (__INIT__.headers) { + Object.assign(headers, __INIT__.headers) } - Object.assign(this.options, __INIT__, options, { url }) + if (options.headers) { + Object.assign(headers, options.headers) + delete options.headers + } + + Object.assign(this.options, __INIT__, options, { url, headers }) this.__next__() return this.defer.promise diff --git a/src/next.es7 b/src/next.es7 index a75ae86..bc1c860 100644 --- a/src/next.es7 +++ b/src/next.es7 @@ -50,11 +50,18 @@ class _Request { options.signal = this.control.signal } - if (__INIT__.headers && options.headers) { - Object.assign(__INIT__.headers, options.headers) + var headers = this.options.headers + + if (__INIT__.headers) { + Object.assign(headers, __INIT__.headers) } - Object.assign(this.options, __INIT__, options, { url }) + if (options.headers) { + Object.assign(headers, options.headers) + delete options.headers + } + + Object.assign(this.options, __INIT__, options, { url, headers }) return this.__next__() }