This component based approach was mainly inspired and adopted by ReactJS. We write the code as components, so that we can import that component and reuse it where we need it. Vue.js offers a single-file component, making the code freely linkable and reusable.
Vue.js offers the best component approach like any other development approach; it can be found in a single .view file. Developers feel as comfortable and relaxed as they don’t have to worry about the extra structure of the component.
In this article we’ll focus on a single file component with the .view extension. So let’s take a look at a very simple example of the View component and see how it works.
Font size: 1em;
Text alignment : Centre;
We write our HTML code in this template tag. In this case, we can also bind variables using the binding syntax of Vue.js, and we can also add other functions using the syntax provided by Vue.js for the corresponding functionality.
- Import of other components and packaging required.
- Variable reporting
- Life cycle hook
- Calculation properties and observers
- And so on and so on…
Here we write the style of the component in CSS, or we can use any preprocessor we want.
This is just a blinking item in Vue.js. Let’s look at the use, organization and flow of data between the components.
Importation and use of components
To use a part, you must import it first. How else would Vue.js know? We can easily import a component by adding the import operator at the beginning of a script tag and declare this component in the component object using the following syntax
After successfully importing a component, we can use it in the model as follows
This way we can easily import the part and use it in any other part.
Just like any other application, the component organization works like a nested tree. For example, a simple website that contains the header, sidebar and some other elements in the container. The organization of the division would look like this.
Photo of Vue.js Official documents
Data flow between components
There may be two types of data streams between the components: From the parental component to the child component
We may use an accessory to send data from a parent component to a child component: Child component – older component
We can send data by triggering an event from the child component and listening to the other side (parent component).
In this article we have gone as far as understanding the main component of Vue.js to the use, hierarchy, organization and implementation of the input, use and interaction know-how between the components. In this article many elements are discussed, but there is also a lot of in-depth knowledge about the components. For more information, please contact Vue.js Official Docs.
best vue extensions for vs code,vue.js visual studio 2019,run vue app locally,vue scaffold visual studio code,vetur autocomplete not working,vscode vue syntax highlighting not working