You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<scriptsetuplang="ts">import { ref, Ref, reactive,isRef,unref,toRef } from"vue";const initial =ref(10)const count =ref(0)// Challenge 1: Update reffunction update(value) {// impl...count.value=value;}/** * Challenge 2: Check if the `count` is a ref object. * Make the output be 1*/console.log(isRef(count)?1:0)/** * Challenge 3: Unwrap ref * Make the output be true*/function initialCount(value:number|Ref<number>) {// Make the output be trueconsole.log(unref(value) ===10)}initialCount(initial)/** * Challenge 4: * create a ref for a property on a source reactive object. * The created ref is synced with its source property: * mutating the source property will update the ref, and vice-versa. * Make the output be true*/const state =reactive({ foo: 1, bar: 2,})const fooRef =toRef(state,'foo') // change the impl...// mutating the ref updates the originalfooRef.value++console.log(state.foo===2)// mutating the original also updates the refstate.foo++console.log(fooRef.value===3)</script>
<template>
<div>
<p>
<span @click="update(count-1)">-</span>
{{ count }}
<span @click="update(count+1)">+</span>
</p>
</div>
</template>
The text was updated successfully, but these errors were encountered:
The text was updated successfully, but these errors were encountered: