fix(client): nextTickの中でonUnmounted呼び出しても効かない可能性がある

This commit is contained in:
syuilo 2022-02-12 17:29:15 +09:00
parent 1c6ab5447d
commit 642a51a558
1 changed files with 6 additions and 6 deletions

View File

@ -180,12 +180,12 @@ const setPosition = () => {
el.value.style.top = top + 'px'; el.value.style.top = top + 'px';
}; };
let loopHandler;
onMounted(() => { onMounted(() => {
nextTick(() => { nextTick(() => {
setPosition(); setPosition();
let loopHandler;
const loop = () => { const loop = () => {
loopHandler = window.requestAnimationFrame(() => { loopHandler = window.requestAnimationFrame(() => {
setPosition(); setPosition();
@ -194,11 +194,11 @@ onMounted(() => {
}; };
loop(); loop();
});
});
onUnmounted(() => { onUnmounted(() => {
window.cancelAnimationFrame(loopHandler); window.cancelAnimationFrame(loopHandler);
});
});
}); });
</script> </script>