on-scope-dispose.uvue 819 字节
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
<template>
  <view class="page">
    <text id="has-current-scope">hasCurrentScope: {{ hasCurrentScope }}</text>
    <button id="create-scope-btn" class="uni-common-mt" @click="createScope">create scope</button>
    <button id="stop-scope-btn" class="uni-common-mt" @click="stopScope">stop scope</button>
  </view>
</template>

<script setup>
  const hasCurrentScope = ref(false)

  let scope = null as EffectScope | null

  const createScope = () => {
    scope = effectScope();
    (scope as EffectScope).run(() => {
雪洛's avatar
雪洛 已提交
17
      hasCurrentScope.value = getCurrentScope() != null
18
      onScopeDispose(() => {
雪洛's avatar
雪洛 已提交
19
        hasCurrentScope.value = getCurrentScope() != null
20 21 22 23 24 25 26 27 28 29
      })
    })
  }

  const stopScope = () => {
    if (scope !== null) {
      (scope as EffectScope).stop()
    }
  }
</script>