节流
useRequest 提供了一个 options.throttleWait 参数,进入节流模式,此时如果频繁触发 run 或者 runAsync,则会以节流策略进行请求。
代码演示
Options
throttle 所有参数用法和效果同 lodash.throttle
| 参数 | 说明 | 类型 | 默认值 |
|---|---|---|---|
| throttleWait | 节流等待时间, 单位为毫秒,设置后,进入节流模式 | number | - |
| throttleLeading | 在节流开始前执行调用 | boolean|Ref<boolean> | true |
| throttleTrailing | 在节流结束后执行调用 | boolean|Ref<boolean> | true |
注意
options.throttleWait支持动态变化。options.throttleLeading支持动态变化。options.throttleTrailing支持动态变化。runAsync在真正执行时,会返回Promise。在未被执行时,不会有任何返回。