Skip to content

Latest commit

 

History

History
35 lines (25 loc) · 2.5 KB

File metadata and controls

35 lines (25 loc) · 2.5 KB

shallow ref easy #Composition API #Reactivity:Advanced

By webfansplz @webfansplz

Take the Challenge    简体中文

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

<script setup lang="ts">
import { shallowRef, watch } from "vue"

const state = shallowRef({ count: 1 })

// Does NOT trigger
watch(state, () => {
  console.log("State.count Updated")
}, { deep: true })

/**
 * Modify the code so that we can make the watch callback trigger.
*/
state.value.count = 2

</script>

<template>
  <div>
    <p>
      {{ state.count }}
    </p>
  </div>
</template>

Back Share your Solutions Check out Solutions