Nuxt3如何检测组件卸载?求beforeUnmount的等价钩子
Nuxt3中对应Vue beforeUnmount的等价钩子
在Nuxt3中,你可以通过以下两种方式实现组件卸载前的逻辑(比如清除定时器),对应Vue的beforeUnmount钩子:
- 选项式API场景:直接使用
beforeUnmount钩子,用法和Vue完全一致:
<script> export default { beforeUnmount() { // 清除定时器 clearInterval(this.timer) }, mounted() { this.timer = setInterval(() => { // 定时器业务逻辑 }, 1000) } } </script>
- 组合式API(
相关产品推荐
相关产品推荐

