0.0.6 • Published 2 years ago

@lgd-utils/axios v0.0.6

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

@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