use-taro-request
TypeScript icon, indicating that this package has built-in type declarations

0.1.1 • Public • Published

use-taro-request

use-taro-request 是基于 taro 及 react 开发的主要用于网络请求的 hooks。

npm npm downloads npm license npm bundle size npm type definitions

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 是否手动触发请求

Readme

Keywords

none

Package Sidebar

Install

npm i use-taro-request

Weekly Downloads

0

Version

0.1.1

License

MIT

Unpacked Size

10.8 kB

Total Files

10

Last publish

Collaborators

  • damonzhang