0.4.2 • Published 3 years ago

@tmaito/fetch v0.4.2

Weekly downloads
8
License
MIT
Repository
-
Last release
3 years ago

@tmaito/fetch NPM version NPM Downloads

基于restfull规范通用的 http 请求库

该库基于axios封装,axios的参数全部都能支持。详见axios官网

Usage

import { fetch, Cookie, CryptoJS, fetchConfig } from ('@tmaito/fetch');

fetchConfig // 可设置默认参数 同 axios.defaults

fetch({
  url: 'xxx/xxx',
  data: {
    arg1: 1
	},
	headers: {
    'x-access-token': 'test'
  },
  method: 'post', // 默认为POST
  cancelRedirect: false, // 是否需要重定向 默认 false
  cancelToken: false, // 是否启动 相同接口多次请求,在前一次接口未结束时,后续接口做取消请求操作
	response: false, // 返回结果是否为 response,默认 true 返回 data
}).then(res => {
  console.log(res)
}).catch(e => {
  console.error(e)
})

Cookie.set(key, value), // 设置
Cookie.get(key), // 获取
Cookie.remove(key) // 移除
// 注意: cookie 针对的 domain 为一级域名


const {
  Decrypt, // 解密方法
	Encrypt, // 加密方法
} = CryptoJS;