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

5 - watch 全家桶

Open undefined-zzk opened this issue 1 year ago • 0 comments

// 你的答案

`

const count = ref(0)

/**

  • Challenge 1: Watch once
  • Make sure the watch callback only triggers once */ watch(count, () => { console.log("Only triggered once") },{once:true})

count.value = 1 setTimeout(() => count.value = 2)

/**

  • Challenge 2: Watch object
  • Make sure the watch callback is triggered */ const state = ref({ count: 0, })

watch(()=>state.value.count, () => { console.log("The state.count updated") })

state.value.count = 2

/**

  • Challenge 3: Callback Flush Timing
  • Make sure visited the updated eleRef */

const eleRef = ref() const age = ref(2) watch(age, () => { console.log(eleRef.value) },{flush:'post'}) age.value = 18

`

undefined-zzk avatar Feb 02 '24 10:02 undefined-zzk