UNPKG

vue-hooks-plus

Version:
21 lines (20 loc) 536 B
"use strict"; const vue = require("vue"); function useTimeout(fn, delay, options) { const immediate = options == null ? void 0 : options.immediate; if (immediate) { fn(); } vue.watchEffect((onInvalidate) => { if (vue.unref(delay) === void 0 || typeof vue.unref(delay) !== "number" || vue.unref(delay) < 0) return; const _deply = vue.unref(delay); const timer = setTimeout(() => { fn(); }, _deply); onInvalidate(() => { clearInterval(timer); }); }); } module.exports = useTimeout;