Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to define a Vue component using the Composition API.
Vue
<script setup> import { ref } from 'vue' const count = ref(0) function increment() { count.value [1] 1 } </script> <template> <button @click="increment">Count: {{ count }}</button> </template>
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-=' will decrease the count instead of increasing it.
Using '*=' or '/=' will multiply or divide the count, which is not intended.
✗ Incorrect
We use += to add 1 to the current count value when the button is clicked.
2fill in blank
mediumComplete the code to bind a reactive property to the template.
Vue
<script setup> import { ref } from 'vue' const message = ref('Hello') </script> <template> <p>{{ [1] }}</p> </template>
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
message.value in the template causes errors.Trying to call
message() is incorrect for refs.✗ Incorrect
In Vue templates, you use the ref variable name directly without .value.
3fill in blank
hardFix the error in the component setup by completing the import statement.
Vue
<script setup> import [1] from 'vue' const count = ref(0) </script>
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Importing
reactive instead of ref causes errors here.Using
computed or watch is not correct for this purpose.✗ Incorrect
The ref function is needed to create reactive references like count.
4fill in blank
hardFill both blanks to create a reactive object and update its property.
Vue
<script setup> import { [1] } from 'vue' const state = [2]({ count: 0 }) function increment() { state.count++ } </script>
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
ref for objects requires different syntax.Importing
computed or watch is not correct here.✗ Incorrect
Use reactive to create a reactive object like state.
5fill in blank
hardFill all three blanks to create a computed property that doubles a count.
Vue
<script setup> import { ref, [1] } from 'vue' const count = ref(1) const double = [2](() => count.value [3] 2) </script>
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
reactive instead of computed for derived values.Using addition
+ instead of multiplication *.✗ Incorrect
Use computed to create a reactive value based on count. Multiply by 2 with *.