1.3.7 • Published 3 years ago

ko-request v1.3.7

Weekly downloads
9
License
ISC
Repository
github
Last release
3 years ago

ko-requset

npm version Linux Build Status

基于axios和fetch封装的request工具,方便设置拦截器,配合swagger可以方便快速配置使用

Install

yarn add @kodesign/ko-requset
npm install @kodesign/ko-request

Axios Usage

参数名描述类型是否必须
beforeRequset发起请求前的回调url => nullfalse
initConfig初始化配置Objectfalse
reqInterceptrequest拦截器(config) => configfalse
resInterceptresponse拦截器(res) => Promisefalse
import { Axios } from '@dtux/ko-request';
const http = new Fetch({
	initConfig: {
		baseURL: '',
		headers: {}
	},
	beforeRequset: (url) => {
		
	},
	reqIntercept: (config, url) => {
		// reqeset Intercept在这里添加loading、 配置token
		return config
	},
	resIntercept: (res, url) => {
		// response Intercept在这里关闭loading
		return Promise.resolve(res);
	}
});

Fetch Usage

参数名描述类型是否必须
baseURL接口地址Stringfalse
initConfig初始化配置Objectfalse
reqInterceptrequest拦截器(config, url) => configfalse
resInterceptresponse拦截器(res, url) => Promisefalse
import { Fetch } from '@dtux/ko-request';
const http = new Fetch({
	baseURL: '',
	initConfig: {
		headers: {
			'Content-Type': 'application/json'
		}
	},
	reqIntercept: (config, url) => {
		// 配置token
		config.headers.Token = sessionStorage.getItem('token')
		
		在这里添加loading、
		return config
	},
	resIntercept: (res, url) => {
		// response Intercept在这里关闭loading
		return Promise.resolve(res);
	}
});


const res = await http.get('/users')
1.3.7

3 years ago

1.3.7-alpha.1

3 years ago

1.3.7-alpha.2

3 years ago

1.3.7-alpha.0

3 years ago

1.3.6

3 years ago

1.2.6

4 years ago