0.0.5 • Published 12 months ago
easy-fetch2 v0.0.5
更新记录
version 0.0.1
目标是让 fetch 发起请求更方便,并且能批量维护请求。
import { Message } from "@arco-design/web-react";
import { createService } from "../lib/service/createService";
import { EasyFetchConfig, ServiceInstance } from "../lib/service";
type ServiceInstanceType = {
test: ServiceInstance<{ a: number }, { b: number }>;
};
const config: Record<keyof ServiceInstanceType, EasyFetchConfig> = {
test: {
url: "/test",
method: "GET",
},
};
const service = createService<ServiceInstanceType>(config, {
async onSuccess(data, response) {
console.log(data, response);
Message.success("请求成功");
},
async onError(error) {
Message.error(error.message);
},
});
service.test({ b: 1 }).then((data) => {
console.log(data);
});
- 支持基本的请求功能。
- 支持 onSuccess 、 onError 的回调函数。
- 支持 GET 、 POST 请求常规请求。