From 763792d7f12d4cce97245dd54ac6e7ec1fc0a2d8 Mon Sep 17 00:00:00 2001 From: yutent Date: Mon, 28 Oct 2024 17:16:12 +0800 Subject: [PATCH] fixed undefined --- package.json | 2 +- src/lib/format.js | 17 +++++++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 09701a9..9e99a22 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@bytedo/fetch", - "version": "2.1.7", + "version": "2.1.8", "description": "全新的ajax封装。分2个版本, 一个基于XMLHttpRequest, 一个基于window.fetch", "main": "dist/next.js", "files": [ diff --git a/src/lib/format.js b/src/lib/format.js index 90a603d..7f8fb99 100644 --- a/src/lib/format.js +++ b/src/lib/format.js @@ -84,13 +84,17 @@ export const Format = { mkFormData(data) { let form = new FormData() for (let i in data) { - let el = data[i] - if (Array.isArray(el)) { - el.forEach(function (it) { + let val = data[i] + if (val === void 0) { + val = '' + } + + if (Array.isArray(val)) { + val.forEach(function (it) { form.append(i + '[]', it) }) } else { - form.append(i, data[i]) + form.append(i, val) } } return form @@ -105,6 +109,11 @@ export const Format = { if (/native code/.test(v)) { return } + + if (v === void 0) { + v = '' + } + let _type = getType(v) v = typeof v === 'function' ? v() : v