Skip to content

8 - effectScope API #1698

Open
Open
@YuinS316

Description

@YuinS316
<script setup lang="ts">
import { ref, computed, watch, watchEffect, effectScope } from "vue"

// use the `effectScope` API to make these effects stop together after being triggered once

const e = effectScope()
const counter = ref(1)
const doubled = computed(() => counter.value * 2)

e.run(() => {
  watch(doubled, () => console.log(doubled.value))
  watchEffect(() => console.log(`Count: ${doubled.value}`))
})
counter.value = 2

setTimeout(() => {
  e.stop()
  counter.value = 4
})
</script>

<template>
  <div>
    <p>
      {{ doubled }}
    </p>
  </div>
</template>

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @YuinS316

        Issue actions

          8 - effectScope API · Issue #1698 · webfansplz/vuejs-challenges