npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

keylion-hooks

v1.1.2

Published

vue3 hooks

Downloads

3

Readme

hooks 工具库

下载

$ npm install keylion-hooks

useRequest

与请求库无关,支持axio、fetch等请求封装库。 用于数据获取的Vue 3组合API,支持SWR、轮询、错误重试、缓存请求

使用

import {useRequest} from "keylion-hooks";

function changeUsername() {
  return new Promise((resolve) => {
    setTimeout(() => {
      resolve({data: 123, code: 123});
    }, 1000);
  });
}
let {data, run} = useRequest(changeUsername, {
  refreshOnWindowFocus: true,
  // focusTimespan: 8000 // 延迟 n 秒 后执行, 并不是每次聚焦都执行,而是过一段时间后可以再次执行
  // pollingInterval: 1000,
  // pollingWhenHidden: true,
});

参数说明

| 参数 | 说明 | 类型 | 默认值 | | ------------------------ | --------------------------------------------------------------------------------------------------------- | ------------ | ------- | | manual | 是否手动控制发送请求 | boolean | false | | pollingInterval | 轮询间隔时间 | number | - | | pollingErrorRetryCount | 轮询次数 | number | - | | pollingWhenHidden | 不在当前屏幕则停止轮询 | boolean | false | | refreshDeps | 依赖刷新 值变化后重新触发请求 | Ref[] | - | | refreshOnWindowFocus | 屏幕聚焦重新请求 | boolean | false | | focusTimespan | 屏幕聚焦重新请求延时(n 秒内重新聚焦请求一次) | number | 1000 | | debounceInterval | 防抖延时 | number | - | | throttleInterval | 节流延时 | number | - | | loadingDelay | 延长 loading 变成 true 的时间 | number | - | | cacheKey | 缓存的唯一 Key (在发送一次新的请求的时候如果有缓存,会先使用缓存的结果值,等到请求完成后替换成请求结果值) | string | - | | cacheTime | 缓存有效时间 | number | - | | staleTime | 如何设置了 staleTime =-1 那么永久保鲜, 在 staleTime 保鲜期间内不再发起请求间 | number | - | | params | 传给接口的参数 | any[] | - | | retryCount | 错误重试次数 | number | - | | onBefore | 请求前触发的生命周期函数 | function | - | | onSuccess | 请求成功触发的生命周期函数 | function | - | | onError | 请求失败触发的生命周期函数 | funciton | - | | onFinally | 请求完成触发的生命周期函数 | function | - |

返回值

useRequest<R extends object, P extends any[]>

| 参数 | 说明 | 类型 | | --------- | ---------------------------------------- | ---------------- | | data | 返回的结果值 | Ref<R> | | error | 错误返回结果 | Ref<Error> | | loading | loading 状态 | Ref<boolean> | | params | 当前传入参数 | P | | run | 错误返回结果 | (...args:P)=>R | | refresh | 使用上一次的 params 请求参数进行重新请求 | (...args:P)=>R | | mutate | 修改 data 的 值 | unknow | | unmount | 结束生命周期时调用函数,清除定时器等 | ()=>void | | cancel | 取消函数 | ()=>void |