forked from mengyxu/noob-components
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
13 lines
283 B
13 lines
283 B
|
6 months ago
|
import { nextTick, Ref, watchEffect, WatchEffect } from "vue";
|
||
|
|
|
||
|
|
export function watchEffectOnce(cond: Ref<any, any>, cb: WatchEffect) {
|
||
|
|
const stop = watchEffect((onCleanup) => {
|
||
|
|
if (cond.value) {
|
||
|
|
nextTick(() => stop());
|
||
|
|
cb(onCleanup);
|
||
|
|
}
|
||
|
|
});
|
||
|
|
|
||
|
|
return stop;
|
||
|
|
}
|