From 0e5c353fbb98dc565d5354c39d3445651c285bcb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=87=E5=A4=A9?= Date: Mon, 31 Aug 2020 17:49:45 +0800 Subject: [PATCH] fixed --- package.json | 2 +- src/index.es7 | 13 ++++++++++--- src/next.es7 | 13 ++++++++++--- 3 files changed, 21 insertions(+), 7 deletions(-) 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__() }