A axios adapter and middleware tool
import axios from 'axios';
import { adapterCacheWrapper } from '@lgd-utils/axios';
const http = axios.create({
baseURL: '/',
// cache will be enabled by default when http method is get
adapter: adapterCacheWrapper(axios.defaults.adapter)
});
http.get('/api/userInfo'); // make real http request
http.get('/api/userInfo'); // use the response from the cache of previous request, without real http request made
http.get('/api/userInfo', { forceUpdateCache: true }); // will forceUpdate the cache and the the real http request invoked
http.get('/api/userInfo', { disableCache: true }); // disable cache manually and the the real http request invoked
- 如果使用 dist/axios.global.prod.js,需要先引入 axios 和 qs
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script src="https://cdn.bootcss.com/qs/6.10.1/qs.min.js"></script> 或
<script src="https://cdn.bootcdn.net/ajax/libs/qs/6.10.1/qs.js"></script>
- @lgd-utils/array - A front-end array tool
- @lgd-utils/cached-storage - 一个具有失效功能的缓存存储库
- @lgd-utils/collection - A front-end collection tool
- @lgd-utils/error - A front-end error tool
- @lgd-utils/html - A front-end html tool
- @lgd-utils/number - A front-end number tool
- @lgd-utils/object - A front-end object tool
- @lgd-utils/polling - A front-end polling tool
- @lgd-utils/regexp - A front-end regexp tool
- @lgd-utils/request-queue - A front-end request-queue tool
- @lgd-utils/screenlog - Bring console.log and so on, on the screen
- @lgd-utils/symbol - A front-end symbol tool
- @lgd-utils/utils - A front-end utils tool
- @lgd-utils/validate - A front-end verification tool
- More…