Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to import a composable function in Vue 3.
Vue
import { [1] } from './useCounter';
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to import a mixin as a composable function.
Using incorrect capitalization or naming.
✗ Incorrect
Composable functions in Vue 3 are usually named starting with 'use' and imported by their exact name.
2fill in blank
mediumComplete the code to add a mixin to a Vue component.
Vue
export default {
[1]: [counterMixin],
setup() {
// component logic
}
}; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'composables' instead of 'mixins'.
Placing mixins inside 'methods' or 'components'.
✗ Incorrect
Mixins are added to the 'mixins' option in Vue components.
3fill in blank
hardFix the error in the composable usage inside the setup function.
Vue
setup() {
const { count, increment } = [1]();
return { count, increment };
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to call a mixin as a function inside setup.
Using incorrect function names.
✗ Incorrect
Composable functions are called inside setup and return reactive state and methods.
4fill in blank
hardFill both blanks to define a mixin and use it in a component.
Vue
const counterMixin = {
data() {
return { count: 0 };
},
methods: {
[1]() {
this.count++;
}
}
};
export default {
[2]: [counterMixin]
}; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Naming the method incorrectly.
Placing mixins under wrong component options.
✗ Incorrect
The method to increase count is named 'increment', and mixins are added in the 'mixins' array.
5fill in blank
hardFill all three blanks to create a composable and use it in a component's setup.
Vue
import { [1] } from './useCounter'; export default { setup() { const { [2], [3] } = useCounter(); return { [2], [3] }; } };
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Importing or using mixins instead of composables.
Using wrong variable names inside setup.
✗ Incorrect
The composable is imported as 'useCounter', and inside setup we extract 'count' and 'increment' from it.