[](https://www.npmjs.com/package/cookie-fetch) [](https://github.com/ljunb/cookie-fetch/blob/master/LICENSE)
npm install cookie-fetch

使用npm:
```
npm install cookie-fetch --saveyarn
用:``
yarn add cookie-fetch
`
import CFetch, { CachePolicy } from 'cookie-fetch';
...
async componentDidMount() {
const url = 'http://food.boohee.com/fb/v1/categories/list';
const options = {cache: CachePolicy.NetworkFirst, timeout: 0.1};
try {
const {result, isCache} = await CFetch.get(url, options);
alert(response: ${result} \n isCache: ${isCache})error: ${error}
} catch (error) {
alert()`
}
}
resolve的结果为Object,key为result、isCache。其中result为序列化后的结果,isCache代表是否从缓存读取的结果。
ForceNetwork | 强制请求网络,请求失败返回null
ForceCache | 强制读取缓存,读取失败返回null方法
Name | Description
---------------- | -----------
get | GET请求方法,使用方式与fetch一致,支持在options中设置timeout
post | POST请求方法,使用方式与fetch一致,支持在options中设置timeout
clearHTTPCacheWithURL | 基于某个请求URL清除HTTP缓存,接受的参数与请求的URL需匹配一致,包括query部分
clearAllHTTPCache | 清除所有的HTTP`缓存