Skip to content

10 - 生命周期钩子 #3104

@wangliang01

Description

@wangliang01
<script setup lang="ts">
import { onMounted, inject, ref, onUnmounted } from "vue"

const timer = inject("timer", ref(null))
const count = inject("count", ref(0))

onMounted(() => {
  timer.value = window.setInterval(() => {
    count.value++
  }, 1000)
})

onUnmounted(() => {
  window.clearInterval(timer.value)
  timer.value = null
})

</script>

<template>
  <div>
    <p>
      Child Component: {{ count }}
    </p>
  </div>
</template>

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions