1.0.5 • Published 2 years ago

nuxt-axios-cache v1.0.5

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

nuxt-axios-cache

// plugins 配置
import {Cache, cacheAdapterEnhancer } from 'nuxt-axios-cache';

export default(context)=>{
	let $axios = context.$axios; // *
	let http = context.$axios.create({
		baseURL,
		headers: { 'Cache-Control': 'no-cache' }, // *
		validateStatus:function(status){
			return status >= 200 && status < 300;
		},
		// *
		adapter:cacheAdapterEnhancer($axios.defaults.adapter,{
			// 是否默认开启 API 缓存
			enabledByDefault:true,
			// 非默认开启 手动设置启用缓存时的 识别字段
			// 例: axios.post(url,data,{__cache:true})
			cacheFlag:'__cache'
		})
	});
	http.interceptors.response.use(function (response) {
		if (response.status === 200) {
			return response.data;
		} else {
			return Promise.reject(response)
		}
	})

	// *
	context.$axios = http;
}
1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago