🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

@chargo/fetch

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@chargo/fetch

公共fetch请求库

latest
Source
npmnpm
Version
1.0.13
Version published
Weekly downloads
18
260%
Maintainers
1
Weekly downloads
 
Created
Source

fetch

Using yarn

yarn add @heisea/fetch

使用方式

import { initFetch } from '@chargo/fetch';

// 创建createFetch函数,参数为axios的配置,具体请参考axios。其中errTipFn为错误提示语的调用函数
// 在response.code为非0的情况下库会调用errTipFn方法,这里的Message.error则为elementui的风格,
// 可以根据ui框架定义不同的风格
const createFetch = initFetch({
  baseURL: Config.baseUrl,
  errTipFn: Message.error
});

/**
 * 中间件, config为请求方法的配置,enhanceFetch为增强的方法,此方法必须返回
 */
const fetch = createFetch([
  function middleware1(config, enhanceFetch) {
    // 请求配置信息相关判断逻辑
    if (config.url === '/demo') {
        config.url = '/public/demo';
    } 
    return enhanceFetch(config);
  }
]);
export default fetch;

Keywords

chargo

FAQs

Package last updated on 08 Dec 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts