Complete the code to create a reactive reference for a count variable.
<script setup> import { [1] } from 'vue' const count = [1](0) </script>
The ref function creates a reactive reference to a value, perfect for primitive types like numbers.
Complete the code to create a reactive object with a name property.
<script setup> import { reactive } from 'vue' const user = reactive({ [1]: 'Alice' }) </script>
The reactive function wraps an object to make all its properties reactive. Here, name is the property we want.
Fix the error in accessing the value of a ref variable in the template.
<template>
<p>Count is: {{ [1] }}</p>
</template>
<script setup>
import { ref } from 'vue'
const count = ref(5)
</script>.value inside the template, which is unnecessary.In Vue templates, you can use a ref variable directly without .value. Vue unwraps it automatically.
Fill both blanks to create a reactive object and update its property.
<script setup> import { [1] } from 'vue' const state = [2]({ count: 0 }) state.count++ </script>
reactive is used to create a reactive object. We import and call reactive to wrap the object.
Fill all three blanks to create a ref, update its value, and display it in the template.
<template>
<p>Message: {{ [1] }}</p>
</template>
<script setup>
import { [2] } from 'vue'
const message = [3]('Hello')
message.value = 'Hi there!'
</script>message.value in the template.We import ref to create a reactive reference. The variable message holds the ref. In the template, we use message directly because Vue unwraps refs automatically.