0
0
Vueframework~5 mins

Reactive data with ref in Vue - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is ref in Vue's Composition API?

ref is a function that creates a reactive reference to a value. It lets Vue track changes to that value and update the UI automatically.

Click to reveal answer
beginner
How do you access the value inside a ref?

You access or change the value inside a ref by using the .value property.

Example: count.value = 5

Click to reveal answer
beginner
Why use ref instead of a normal variable in Vue?

Normal variables are not reactive. ref makes the variable reactive so Vue knows when it changes and updates the UI automatically.

Click to reveal answer
intermediate
Can ref hold objects or arrays?

Yes, ref can hold any type of value, including objects and arrays. Vue will track changes inside them reactively.

Click to reveal answer
intermediate
What happens if you assign a new object to a ref?

When you assign a new object to a ref using .value, Vue updates the reactive reference and the UI updates accordingly.

Click to reveal answer
How do you create a reactive number with ref in Vue?
Aconst count = ref(0)
Bconst count = reactive(0)
Cconst count = 0
Dconst count = ref.value(0)
How do you update the value inside a ref named count?
Acount = 5
Bcount.value = 5
Ccount.set(5)
Dcount.update(5)
Which of these is true about ref?
AIt only works with primitive values
BIt disables reactivity
CIt is used to create components
DIt makes variables reactive
If you have const user = ref({ name: 'Anna' }), how do you change the name?
Auser.setName('Bob')
Buser.name = 'Bob'
Cuser.value.name = 'Bob'
Duser.value = 'Bob'
What happens if you assign a new array to a ref variable?
AVue updates the reactive reference and UI
BThe array becomes non-reactive
CVue throws an error
DVue ignores the change
Explain how ref works in Vue and why it is useful.
Think about how Vue tracks changes to variables.
You got /4 concepts.
    Describe how you would update a property inside an object stored in a ref.
    Remember .value holds the actual object.
    You got /4 concepts.