0.1.1 • Published 1 year ago
use-taro-request v0.1.1
use-taro-request
use-taro-request 是基于 taro 及 react 开发的主要用于网络请求的 hooks。
Installation / 安装
npm
npm install use-taro-request --save
yarn
yarn add use-taro-request
Config / 配置
使用 taroRequestConfig
在程序入口文件,app.tsx
或者main.ts
等中导入并全局配置
import { taroRequestConfig } from "use-taro-request";
taroRequestConfig({
baseUrl: "https://example.com",
header: {}
// ...
});
Usage / 使用
import { useTaroRequest } from "use-taro-request";
const { data, loading, error, refetch } = useTaroRequest({ url: "/list" });
manual / 手动触发请求
通过 manual
属性配置依赖请求,当传入 true
时,将需要自己手动触发 refetch
import { useTaroRequest } from "use-taro-request";
const { data, loading, error, refetch } = useTaroRequest(
{
url: "/list",
params: {
//...
}
},
{ manual: true }
);
taro 请求配置
Property | Type | Default | Description |
---|---|---|---|
baseUrl | string | '' | 基础网络地址 |
header | object | {} | 请求头 |
timeout | number | 0 | 请求 timeout |
taro request hooks 配置
Property | Type | Default | Description |
---|---|---|---|
manual | boolean | false | 是否手动触发请求 |