0.2.0 • Published 1 year ago
@kcuf/fetcher-fetch v0.2.0
@kcuf/fetcher-fetch
@kcuf/fetcher底层 fetch 封装
原生 fetch 特点:
- 不支持
timeout(这里模拟掉了) - HTTP 错误状态(400、500 等),仍然 resolve
- 默认不携带 cookie,必须
{ credentials: 'include' } - 不支持 progress 事件,因此上传需要感知进度的还得用 XHR
- 当
body和headers类型有耦合body为URLSearchParams|FormData|Blob,headers中不可有'Content-Type'headersContent-Type为'application/json',用JSON.stringify处理bodyheadersContent-Type为'application/x-www-form-urlencoded',用qs或URLSearchParams处理body