Skip to content

Commit e9e89a0

Browse files
authored
Merge pull request #45 from xiaoxiangmoe/master
feat: add transformRequestOption
2 parents 188b3a8 + a694119 commit e9e89a0

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ $ npm i axios axios-miniprogram-adapter
7272
import axios from 'axios'
7373
import mpAdapter from 'axios-miniprogram-adapter'
7474
axios.defaults.adapter = mpAdapter
75+
// or with extra config transformer
76+
axios.defaults.adapter = config => mpAdapter(config, { transformRequestOption: requestOption => { /* modify requestOption here */ return requestOption } })
7577
```
7678

7779
### 2.如果你没有使用任何脚手架工具

src/index.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@ const isJSONstr = str => {
1313
return false
1414
}
1515
}
16-
export default function mpAdapter (config: AxiosRequestConfig) :AxiosPromise {
16+
export default function mpAdapter(config: AxiosRequestConfig, {
17+
transformRequestOption = requestOption => requestOption
18+
}: {
19+
transformRequestOption?: (requestOption: any) => any
20+
} = {}): AxiosPromise {
1721
const request = getRequest()
1822
return new Promise((resolve, reject) => {
1923
let requestTask: void | WechatMiniprogram.RequestTask
@@ -88,6 +92,6 @@ export default function mpAdapter (config: AxiosRequestConfig) :AxiosPromise {
8892
if (requestData !== undefined) {
8993
mpRequestOption.data = requestData
9094
}
91-
requestTask = request(transformConfig(mpRequestOption))
95+
requestTask = request(transformRequestOption(transformConfig(mpRequestOption)))
9296
})
9397
}

0 commit comments

Comments
 (0)