vue-hooks-plus
Version:
Vue hooks library
21 lines (20 loc) • 536 B
JavaScript
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;
;