Skip to content

CrazyaCoding/fetch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

fetch

install

npm i @shangs/fetch --save-dev

useage

import fetchs from '@shangs/fetch';
let config = {
	mode: 'no-cors',
	credentials: 'same-origin',
	headers: {
		contentType: 'application/json',
		accept: 'application/json',
	}
	timeout: 5000
};
// GET
fetchs
	.get('http://localhost:3003/students', config)
	.then(response => {
		console.log(response);
	})
	.catch(e => {
		console.log(e);
	});

fetchs
	.get('http://localhost:3003/students', {params: {name: 'Lily'}}, config)
	.then(response => {
		console.log(response);
	})
	.catch(e => {
		console.log(e);
	});

// POST
fetchs
	.post(' http://localhost:3003/students', data, config)
	.then(response => {
		console.log(response);
	})
	.catch(e => {
		console.log(e);
	});
// interceptors
fetchs.interceptors.request(config => {
	config = {
		timeout: 5000,
		mode: 'cors',
		credentials: 'include'
	};
	return config;
});

fetchs.interceptors.response(
	reponse => {
		return reponse;
	},
	err => {}
);

About

fetch整理

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published