InterviewSolution
Saved Bookmarks
| 1. |
What are Components in Vue.js? Show how to create one inside a Vue instance. |
|
Answer» In Vue.js component
Steps to create a Vue component called ‘ComponentOne’ INSIDE the Vue instance. Step 1: Create the component by defining a COMMON element of the UI(User interface) to be displayed. Save the file with name ComponentFirst.vue <template> <div><h1>This is coming from component First</h1></div> </template>The component consists of an h1 tag nested in div tag to print ‘This is coming from component First’ at the size of heading one. Step 2: Define the vue instance in which the component is imported (included) <script> import ComponentOne from './ComponentFirst.vue' export default { components: { ComponentFirst } </script> <template> < h1 >Here is the reused component!</h1> <ComponentFirst /> <ComponentFirst /> </template>>> Output
|
|