You might have heard about vue.js. People will recommend you to use vue.js to simplify single page application coding. So, how does it actually simplify it?
It simplifies it by dividing different parts of app into what we call components. These components have different code; and hence are stored in separate files for compartmentalization of code. Why have all the components in a single HTML file when we can have it in different files. Now what Vue or any other JS framework will do under the hood is it will converge all the components into a single file based on what you need. If you need Login page then you can insert a login page. Then after the user has logged in, you can remove the login page and instead of moving to another page it remains on the same page and just remove the component and updates it with a new component.
Now you'll ask that why do we need a JS framework to do that because JS will take a lot more time to render than to simply request a new HTML page.
Here comes the computations that you can do under the hood in the component. You can make dynamic pages. Whenever the user has submitted a form then you can push the new content or remove the previous content of the page without reloading the whole page. Also, you can define several functions that can be performed on the data entered by the user.
Now, you will ask that we can add onsubmit function and we can make a function in normal JS. Then why should we use Vue.js. Here comes the state management.
All components have a state. By state what we mean is the state of an element at that current time. For example: an empty input field, user has pressed submitted button, now on submit we will update the database at the server and on the client side. Over here you can save the data at the place of one component and use that anywhere in your app, in any component. This will lead to update of the data in every component's HTML without reloading the whole page.
Now this will lead to a simpler codebase in the long run if you have to scale the app. Else it will lead to a very long JS file that will be so difficult to understand that after a year you yourself will not understand what you have written. This is from my own experience. I made a single page application that had so many functions that even after naming the functions properly, after a month only I was unable to understand the code myself. And ended up leaving it.
At all, devs love Vue for several reasons. Concluding the discussion, I want to provide you with four key strengths of Vue.js and its community:
- Great flexibility which facilitates interaction with different libraries and suits different strategies, such as the development of PWAs.
- Optimal performance that is available thanks to the minimalism of the tool. Actually, Vue.js is even smaller than 20 KB.