Very similar to native HTML elements, Vue allows us to create custom elements using its own component model.
Test your knowledge on Single File Components of Vue 3.
Components allow us to split the UI into independent and reusable pieces, and think about each piece in isolation. It's common for an app to be organised into a tree of nested components.
Single file components - aka SFC - encapsulate custom content and login in them, and are mostly made up of script, template and style tags with .vue
file extension.
When SFCs are not using build step, they can be written as a plain JavaScript object - but only using Vue-specific options - in .js
file extension.
What is the purpose of a Single File Component (SFC) in Vue.js?
What is the purpose of the ref and reactive function in the Composition API?
How do you access component props, title, inside JavaScript section of the Vue 3 component?
Select all valid in-built directives from the following list.
v-memo: Skips updating a subs-tree of the template when the values of supplied array items remain unchanged.
v-once: Renders the element and component once only, and skip future updates.
v-pre: Skips compilation for an element and all its children.
v-cloak: Used to hide un-compiled template until it is ready.
v-cloak in <style> tag:
[v-cloak] {
display: none;
}
Which of the following statements are true for v-on directive?
<slot> is a built-in component provided by Vue. Which of the following statements are true for custom element <slot>?
What does v-slot:item
indicate in the code sample below?
<InfiniteScroll>
<template v-slot:item="slotProps">
<div class="item">
{{ slotProps.item.text }}
</div>
</template>
</InfiniteScroll>
v-for
directive is used to render the element or template block multiple times based on the given data. Select all acceptable data types for v-for
directive.
v-model is used to create a two-way binding on a form input element or a component. Which of the following elements are applicable for v-model directives?
Sometime the required component to render is not known upfront, or you may need to switch between components. For such use-cases, Vue provided in-built component called <component>
which accepts :is
props. :is props can accept:
<component :is="tabs[currentTab]">
</component>
When switching existing component with a new component using <component :is="">
, the existing component is unmounted and become inactive when it is switched with the new component. How can you force this inactive component to stay alive?