0
0
Vueframework~10 mins

Options API vs Composition API decision in Vue - Interactive Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to define a reactive data property in the Options API.

Vue
export default {
  data() {
    return {
      message: [1]
    };
  }
}
Drag options to blanks, or click blank then click option'
Aref('Hello Vue!')
B'Hello Vue!'
Ccomputed(() => 'Hello Vue!')
Dreactive('Hello Vue!')
Attempts:
3 left
💡 Hint
Common Mistakes
Using Composition API functions like ref() inside data() in Options API.
2fill in blank
medium

Complete the code to create a reactive variable using the Composition API.

Vue
<script setup>
import { [1] } from 'vue';
const count = [1](0);
</script>
Drag options to blanks, or click blank then click option'
Aref
Breactive
Ccomputed
Dwatch
Attempts:
3 left
💡 Hint
Common Mistakes
Using reactive() instead of ref() for primitive values.
3fill in blank
hard

Fix the error in the Options API method to correctly access data property.

Vue
export default {
  data() {
    return {
      count: 0
    };
  },
  methods: {
    increment() {
      this.[1]++;
    }
  }
}
Drag options to blanks, or click blank then click option'
Acount
Bthis.count
Ccount()
Dincrement
Attempts:
3 left
💡 Hint
Common Mistakes
Writing this.this.count or calling count as a function.
4fill in blank
hard

Fill both blanks to create a computed property in the Composition API.

Vue
<script setup>
import { [1] } from 'vue';
const count = ref(0);
const double = [2](() => count.value * 2);
</script>
Drag options to blanks, or click blank then click option'
Acomputed
Bref
Creactive
Dwatch
Attempts:
3 left
💡 Hint
Common Mistakes
Using ref() instead of computed() for derived values.
5fill in blank
hard

Fill all three blanks to define a reactive object and a method to update it in the Composition API.

Vue
<script setup>
import { [1], [2] } from 'vue';
const state = [3]({ count: 0 });
function increment() {
  state.count++;
}
</script>
Drag options to blanks, or click blank then click option'
Areactive
Bref
Ccomputed
Dwatch
Attempts:
3 left
💡 Hint
Common Mistakes
Using ref() for objects instead of reactive().