且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Vue.js 使用 axios 缓存 http 请求

更新时间:2022-12-26 20:24:24

你可以查看这个扩展https://github.com/kuitos/axios-extensions

这里是基本用法示例,希望对您有帮助

Here is the basic usage example, I hope it helps

import axios from 'axios';
import { cacheAdapterEnhancer } from 'axios-extensions';

const http = axios.create({
    baseURL: '/',
    headers: { 'Cache-Control': 'no-cache' },
    // cache will be enabled by default
    adapter: cacheAdapterEnhancer(axios.defaults.adapter)
});

http.get('/users'); // make real http request
http.get('/users'); // use the response from the cache of previous request, without real http request made
http.get('/users', { cache: false }); // disable cache manually and the the real http request invoked