-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
13 changed files
with
82 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,5 +8,6 @@ module.exports = { | |
}, | ||
globals: { | ||
wx: true, | ||
FormData: true, | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,6 +47,7 @@ module.exports = { | |
'middleware', | ||
'mock', | ||
'export-utils', | ||
'form-data', | ||
'../config/', | ||
], | ||
}, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# FormData <Badge text="1.3.0+"/> | ||
## 发送二进制数据 | ||
日常使用中,除了简单的字符串参数以外,有时也会遇到需要发送二进制数据的场景,例如上传文件。 | ||
|
||
在旧版的 `tua-api` 中若是遇到这种请求,也能发送但比较繁琐。 | ||
|
||
```js | ||
const formData = new FormData() | ||
|
||
imgUploadApi.userUpload(null, { | ||
reqFnParams: { reqParams: formData }, | ||
axiosOptions: { transformRequest: null }, | ||
}) | ||
``` | ||
|
||
如上例所示,借助第二个参数[运行时配置](../config/runtime.md)设置了:数据、 `transformRequest`。 | ||
|
||
而在新版本的 `tua-api` 中,只要这么调用即可: | ||
|
||
```js | ||
const formData = new FormData() | ||
|
||
imgUploadApi.userUpload(formData) | ||
``` | ||
|
||
实现原理是 `tua-api` 在底层判断出接收的接口参数是 `FormData` 类型的数据,自动设置了 `transformRequest`。 | ||
|
||
> 小程序端暂时建议使用原生的 `wx.uploadFile`。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
export * from './fp' | ||
export * from './mp' | ||
export * from './env' | ||
export * from './judge' | ||
export * from './logger' | ||
export * from './params' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export const isWx = () => ( | ||
typeof wx !== 'undefined' && | ||
typeof wx.request === 'function' | ||
) | ||
|
||
export const isFormData = (val) => ( | ||
(typeof FormData !== 'undefined') && | ||
(val instanceof FormData) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
module.exports = { | ||
env: { jest: true } | ||
env: { jest: true }, | ||
globals: { | ||
FormData: true, | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters