Skip to content

Commit

Permalink
fix(vue3-hooks): debounce
Browse files Browse the repository at this point in the history
修复debounce跟预期不一致的问题
  • Loading branch information
mengxinssfd committed Mar 10, 2023
1 parent 64d98f6 commit 7486b25
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/vue3-hooks/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export interface Debounce {
/**
* 第一次立即执行
*/
immediate?: boolean;
leading?: boolean;
/**
* 延迟时间
*/
Expand Down
4 changes: 2 additions & 2 deletions packages/vue3-hooks/src/useRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ import type { FN, State, Options, AllOptions } from './types';
* @param [options.immediate=false] 立即执行
* @param {{}?} options.debounce 防抖
* @param options.debounce.delay 延时
* @param [options.debounce.immediate=false] 第一次立即执行
* @param [options.debounce.leading=false] 第一次立即执行;假如只调用了一次请求,那么会执行首尾两次调用
* @param {{}?} options.throttle 节流
* @param options.throttle.interval 间隔
* @param [options.throttle.leading=true] 第一次立即执行
Expand Down Expand Up @@ -95,7 +95,7 @@ export function useRequest<
} = options as AllOptions;

if (_debounce) {
request = debounce(request, _debounce.delay, _debounce.immediate);
request = debounce(request, _debounce.delay, _debounce.leading);
} else if (_throttle) {
const { interval, ...opts } = _throttle;
request = throttle(request, interval, opts);
Expand Down

0 comments on commit 7486b25

Please sign in to comment.