vuejs-challenges icon indicating copy to clipboard operation
vuejs-challenges copied to clipboard

6 - 浅层 ref

Open isolcat opened this issue 3 years ago • 0 comments
trafficstars

// 你的答案
<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>

isolcat avatar Aug 08 '22 13:08 isolcat