1.2.0 • Published 8 months ago

vue-ahooks v1.2.0

Weekly downloads
-
License
-
Repository
-
Last release
8 months ago

vue-ahooks

  • 安装: npm install vue-ahooks
import {
  useAwaitTo,
  useDebounceFn,
  useThrottleFn,
  useMap,
  useLockFn,
  useToggle,
  useTimeout,
  useRafTimeout,
  useDebounceWatch,
} from "vue-ahooks";
/**
 * @ const [state, { set, toggle  }] = useToggle(defaultValue, reverseValue)
 * @ state 当前状态
 * @ toggle 根据defaultValue,reverseValue反转
 */
const [state, { set }] = useToggle();
/**
 * @ params requset(Promise)
 * @ return err(异常 | null), data(Promise成功状态下数据)
 */
const [err, data] = await useAwaitTo(requset());

/**
 * @ params fn(需装饰函数)
 * @ return run(执行函数)
 */
const run = await useLockFn(fn);

/**
 * @ params fn(需装饰函数), time(节流间隔)
 * @ return run(已被装饰函数)
 */
const [run] = useThrottleFn(fn, time);

/**
 * @ params fn(需装饰函数), time(防抖间隔)
 * @ return run(已被装饰函数)
 */
const [run] = useDebounceFn(fn, time);

/**
 * @ params initialValue?: 初始函数
 * @ return type Actions<K, T> = {
  set: (key: K, value: T) => void
  get: (key: K) => T | undefined
  remove: (key: K) => void
  has: (key: K) => boolean
  clear: () => void
  setAll: (newMap: MapValue<K, T>) => void
  reset: () => void
}
 */
const [Map, Actions] = useMap(initialValue);

/**
 * @ params deps(依赖) effect(执行函数) options(同watch参数)
 * @ return Null
}
 */
useDebounceWatch(deps, effect, options);

/**
 * @ const clearTimeout = useRafTimeout(fn, delay)
 * @ fn(待执行函数), delay(等待秒数,默认16)
 * @ return clearTimeout
 */
useRafTimeout(() => {
  fn();
}, 1000);
1.2.0

8 months ago

1.1.3

8 months ago

1.1.2

8 months ago

1.1.1

8 months ago

1.1.0

8 months ago

1.0.8

8 months ago

1.0.7

8 months ago

1.0.6

9 months ago

1.0.5

9 months ago

1.0.3

10 months ago

1.0.2

10 months ago

1.0.1

10 months ago

1.0.0

10 months ago