-
-
Notifications
You must be signed in to change notification settings - Fork 196
Open
Description
// 你的答案
<script setup lang="ts">
import { ref, computed, watch, watchEffect, effectScope } from "vue"
const counter = ref(1)
const doubled = computed(() => counter.value * 2)
// use the `effectScope` API to make these effects stop together after being triggered once
const scope = effectScope()
scope.run(() => {
watch(doubled, () => {
console.log(doubled.value);
scope.stop()
})
watchEffect(() => {
console.log(`Count: ${doubled.value}`);
scope.stop()
})
})
counter.value = 2
setTimeout(() => {
counter.value = 4
})
</script>
<template>
<div>
<p>
{{ doubled }}
</p>
</div>
</template>