@lgd-utils/axios
TypeScript icon, indicating that this package has built-in type declarations

0.0.6 • Public • Published

@lgd-utils/axios

Bundle size MIT NPM downloads NPM version lodash npm styled with prettier

A axios adapter and middleware tool

Usage

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>

Contribute

Documentation

Related

Package Sidebar

Install

npm i @lgd-utils/axios

Weekly Downloads

0

Version

0.0.6

License

MIT

Unpacked Size

542 kB

Total Files

11

Last publish

Collaborators

  • lgd.huafeeng