1.0.7 • Published 4 years ago

@aligov/util-request v1.0.7

Weekly downloads
-
License
ISC
Repository
gitlab
Last release
4 years ago

介绍

基于 axios 为营商开发的请求工具

基础使用方法

注册请求方法,可以定制不同交互组件

iimport React from 'react';
import ReactDOM from 'react-dom';
import Notification from '@alifd/next/es/notification/index';
import '@alifd/next/dist/next.css';
import { createRequest } from "@aligov/util-request"

const request = createRequest({
    type: "xhr",
    ErrorComponent: (errMsg) => Notification.open({
      title: "服务器错误",
      content: errMsg,
    })
  })
const Index = () => {

  const onClick = () => {
    request({
        url: `/policy/queryPolicyGuide`,
        method: `POST`,
        data: {
          policyCode: 2
        }
    }).then(console.log)
  }
  return <div onClick={onClick}>Hello React!</div>;
};

ReactDOM.render(<Index />, document.getElementById('root'));

统一拦截请求

对已经开发的工程,定制赣州拦截请求

iimport React from 'react';
import ReactDOM from 'react-dom';
import { hackGanzhouRequest } from "@aligov/util-request"

// 拦截注册,需要放在请求之前
hackGanzhouRequest();

const Index = () => {
  React.useEffect(() => {
    fetch('/users/test')
    Axios.post('/user', {
      firstName: 'Fred',
      lastName: 'Flintstone'
    })
  })
  return <div>Hello React!</div>;
};

ReactDOM.render(<Index />, document.getElementById('root'));

API

type: "xhr" | "ganzhou"; ErrorComponent?: (errMsg: string) => any

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago