附件判断增加Blob类型
parent
0735b4452d
commit
7983cb0b16
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@bytedo/fetch",
|
||||
"version": "2.1.1",
|
||||
"version": "2.1.2",
|
||||
"description": "全新的ajax封装。分2个版本, 一个基于XMLHttpRequest, 一个基于window.fetch",
|
||||
"main": "dist/index.js",
|
||||
"files": [
|
||||
|
|
|
@ -127,7 +127,10 @@ class _Request {
|
|||
params = options.body
|
||||
} else {
|
||||
for (let k in options.body) {
|
||||
if (toS.call(options.body[k]) === '[object File]') {
|
||||
if (
|
||||
toS.call(options.body[k]) === '[object File]' ||
|
||||
toS.call(options.body[k]) === '[object Blob]'
|
||||
) {
|
||||
hasAttach = true
|
||||
break
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ export const decode = decodeURIComponent
|
|||
function serialize(p, obj, query) {
|
||||
var k
|
||||
if (Array.isArray(obj)) {
|
||||
obj.forEach(function(it, i) {
|
||||
obj.forEach(function (it, i) {
|
||||
k = p ? `${p}[${Array.isArray(it) ? i : ''}]` : i
|
||||
if (typeof it === 'object') {
|
||||
serialize(k, it, query)
|
||||
|
@ -84,7 +84,7 @@ export const Format = {
|
|||
for (let i in data) {
|
||||
let el = data[i]
|
||||
if (Array.isArray(el)) {
|
||||
el.forEach(function(it) {
|
||||
el.forEach(function (it) {
|
||||
form.append(i + '[]', it)
|
||||
})
|
||||
} else {
|
||||
|
@ -99,13 +99,13 @@ export const Format = {
|
|||
}
|
||||
|
||||
let arr = []
|
||||
let query = function(k, v) {
|
||||
let query = function (k, v) {
|
||||
if (/native code/.test(v)) {
|
||||
return
|
||||
}
|
||||
|
||||
v = typeof v === 'function' ? v() : v
|
||||
v = toS.call(v) === '[object File]' ? v : encode(v)
|
||||
v = toS.call(v) === '[object File]' || toS.call(v) === '[object Blob]' ? v : encode(v)
|
||||
|
||||
arr.push(encode(k) + '=' + v)
|
||||
}
|
||||
|
|
|
@ -104,7 +104,10 @@ class _Request {
|
|||
}
|
||||
} else {
|
||||
for (let k in options.body) {
|
||||
if (toS.call(options.body[k]) === '[object File]') {
|
||||
if (
|
||||
toS.call(options.body[k]) === '[object File]' ||
|
||||
toS.call(options.body[k]) === '[object Blob]'
|
||||
) {
|
||||
hasAttach = true
|
||||
break
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue