Skip to content

Lifecycle Hooks easy #Composition API #Lifecycle

By webfansplz @webfansplz

Take the Challenge    简体中文

For this challenge, you'll use the Composition API: Lifecycle Hooks to complete the challenge. Here's what you need to implement 👇:

// Child.vue

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

const timer = inject('timer')
const count = inject('count')


onMounted(() => {
  // The timer will work abnormally when the child component is toggled. Lets fix it.
  timer.value = window.setInterval(() => {
    count.value++
  }, 1000)
})

</script>

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

Share your Solutions Check out Solutions