You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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(
相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.21 14:12:05