Skip to content

10 - 生命周期钩子 #2228

Open
Open
@csw0831

Description

@csw0831
<script setup lang="ts"> import { onMounted, inject, onUnmounted } from "vue" const timer = inject("timer") const count = inject("count") onMounted(() => { timer.value = window.setInterval(() => { count.value++ }, 1000) }) onUnmounted(() => { clearInterval(timer.value) }) </script>

Child Component: {{ count }}

// 你的答案

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions