vuejs-challenges icon indicating copy to clipboard operation
vuejs-challenges copied to clipboard

10 - 生命周期钩子

Open coderwyd opened this issue 3 years ago • 0 comments

// 你的答案
<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 (() => {
    window.clearInterval(timer.value)
  })
  

</script>

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

coderwyd avatar Sep 01 '22 06:09 coderwyd