Code

Vue.js: What It Is, How It Works, and How It Differs from React

Vue.js: What It Is, How It Works, and How It Differs from React

Course with employment: "Frontend Developer Profession"

Learn more

Frontend Developer at LightBox with a passion for the gaming industry. In his spare time, he enjoys traveling and actively uses Vue.js, as well as JavaScript mapping libraries, in his projects.

Vue.js is a popular JavaScript framework developed by Evan Yu in 2012. At the time, Evan was working at Google, where he had the opportunity to become familiar with technologies such as Backbone.js and Angular. The experience gained while working with these frameworks inspired him to create his own solution. Initially conceived as a pet project, Vue.js quickly gained popularity due to its simplicity, flexibility, and powerful capabilities for creating user interfaces. This framework is ideal for both small and large applications, making it an excellent choice for developers looking to build web applications efficiently and quickly.

Vue.js has become extremely popular since its release in 2015, which was due to a tweet by Taylor Otwell, the creator of the well-known PHP framework Laravel. This tweet caught the attention of developers and contributed to the rapid growth of the community around Vue.js. Since then, the framework has established itself as one of the most convenient and effective tools for building user interfaces, providing flexibility and ease of integration into existing projects. Thanks to an active community and regular updates, Vue.js continues to be a relevant choice for developers looking to build modern web applications.

Current status of learning React: Too difficult. I chose to learn Vue.js as it feels simpler and has an attractive website. Vue.js offers an intuitive interface and a low learning curve, making it a great choice for developers looking to quickly master a framework.

After Vue.js was released, it quickly gained popularity among Laravel developers and began to expand beyond that community. If you want to delve into the details of the creation of Vue.js, I recommend checking out the documentary "Vue.js: The Documentary" by Honeypot, which is available on YouTube. This film will give you a better understanding of the working principles and philosophy of Vue.js, and will also introduce you to its community and development.

Evan Yu initially chose the name Seed.js for his framework. However, when he came to the point of publishing the package on npm, he discovered that this name was already in use. This situation forced Evan to look for a new name for his project, which eventually led to the creation of Vue.js, which has become a popular tool for developing user interfaces.

Evan decided to create a library for working with views and models. He knew that the name should reflect the essence of the project, so he chose the word "view". However, written this way, it looked too simple and inexpressive. While researching translations of the word "view" into other languages, he came across the French "vue", which he liked. Moreover, this name turned out to be available in npm, which became an additional advantage for its project.

Many years have passed since its inception, and Vue.js has become a widely known and sought-after framework all over the world. Currently, it is an open-source project, in the development of which numerous developers from different countries participate. Vue.js continues to gain popularity due to its simplicity, flexibility, and powerful capabilities for creating user interfaces.

Vue.js continues to be very popular among developers. For a long time, this framework held the first place by the number of stars on GitHub, which indicates its high level of trust and demand in the community. Although some other projects have now surpassed it in this indicator, Vue.js still remains one of the leaders among JavaScript frameworks, due to its simplicity, flexibility, and rich ecosystem.

Vue.js has high-quality documentation, which serves as a model for creating official documentation for various tools and frameworks. Indeed, working with this documentation is a pleasure thanks to its structure and accessible information.

How Vue.js Works

Vue.js, like React, is based on the concepts of components and state. These key elements allow developers to create interactive user interfaces. Unlike React, Vue.js offers a more flexible approach to state management, which simplifies the development process and improves application performance. Understanding these fundamentals is essential for using Vue.js effectively in developing modern web applications.

Single-file components are the most popular way to organize code in Vue.js. Each Vue.js component is a self-contained and reusable unit stored in a separate file with the .vue extension. This file consists of three sections: template, script, and style. The template section is responsible for the presentation, the script section contains the business logic and data model, and the style section defines the component's styles. Using single-file components simplifies the development, maintenance, and testing of Vue.js applications, allowing developers to organize code more efficiently and in a structured manner. This makes them an ideal choice for creating scalable and maintainable applications.

Web applications are formed from components, which are building blocks that include a view, model, and styles. These elements interact with each other to create functional and visually appealing interfaces. Using such components allows developers to efficiently create and maintain complex applications.

Declarative, Reactive, and Progressive

Vue.js is based on the principle of declaratively displaying data in the DOM using simple templates. This declarative approach is fundamental to any framework and is often one of the reasons for its development. Vue.js allows developers to easily bind data to the view, providing high flexibility and efficiency in creating user interfaces. Using declarative programming simplifies the development process, allowing you to focus on the logic of the application, rather than manipulating the DOM.

Declarative programming refers to an approach in which the developer specifies what needs to be done, while the framework automatically performs all the necessary operations. This method contrasts with the imperative style of vanilla JavaScript, where the programmer must describe each action step by step. The declarative approach simplifies development, improves code readability, and allows developers to focus on the end result, making it a popular choice among modern developers.

In JavaScript, it's important not only to outline the essence of the task but also to clearly define the execution logic step by step. This includes clearly defining the algorithm, which helps avoid errors and optimize the development process. Proper code structure and sequence of actions make it easier for developers to understand and modify the program in the future. Therefore, it is recommended to pay attention to each stage of the task, from requirements analysis to testing and debugging. This approach not only improves the quality of the final product but also promotes more efficient work of the development team.

  • Work with HTML elements, accessing them via id, classes, CSS selectors;
  • Attach and remove event handlers via addEventListener / removeEventListener;
  • Change something in specific DOM nodes when data changes (for example, change text via textContent), and so on.

Vue.js is distinguished by its declarative nature, which makes it convenient for developing interfaces. It offers many directives that allow you to easily and intuitively manage HTML elements. Among them are v-bind, v-for, v-if, v-show, v-html, and others. These directives help developers effectively implement dynamic data updates and component state management, which significantly simplifies the process of creating user interfaces. Using Vue.js with its powerful tools allows you to optimize development and improve the performance of web applications.

Vue.js Declarativity vs. React Declarativity

React also adheres to the declarative philosophy, but it should be noted that this concept is relative. Let's consider two Vue directives as an example: v-for and v-show, and compare them with similar capabilities in React. This will allow us to better understand how both technologies implement the principles of declarative programming and how they affect the development of user interfaces. Comparing these tools will help us identify their strengths and weaknesses, as well as understand in which cases it is preferable to use each technology.

The code contains an array of articles objects containing information about articles. The task is to display the value of the title property for each object. Depending on the application logic, it's also necessary to decide whether to show or hide the paragraph with the text "These articles are available for download." This approach allows for flexible control over the display of information and improves the user experience by providing the user with access to the necessary data in a convenient format.

Let's pay attention to the presentation logic. Effective organization of information plays a key role in user perception of content. A clear structure and sequence of presentation help readers quickly find the information they need and digest it. When formatting content, it's important to use headings and subheadings that highlight main ideas and create visual order. It's also worth considering that the use of lists and paragraphs improves the readability of the text. It's important that each element is logically connected to the previous one, forming a holistic perception of the information presented. By focusing on these aspects, we can significantly improve the effectiveness of communication.

Of course, I'm happy to help you with text editing. Please provide the actual text to be reworked.

To display an array in Vue.js, the v-for directive is used within the tag. The value is set to "article in articles," where "articles" represents an array available in the component, and "article" denotes a single element to be displayed on each loop iteration. Using v-for allows you to efficiently create lists and dynamically display data, making Vue.js a powerful tool for developing interactive user interfaces.

In this process, we iterate through the entire array and display the «title» property for each article using the expression «article.title». The value enclosed in double curly braces represents an interpolation that links the data model with the visual representation. This allows for dynamic generation of content on the page, ensuring that the information is relevant to users. By ensuring proper binding of data and representation, we improve the user experience and make the site more interactive.

The v-show directive modifies the display property of an element, switching it between «none» and «initial» depending on the specified value. In this example, if the isShow variable is true, the element will be visible. If the value is false, the element will be hidden. This directive is convenient for controlling the visibility of elements on the page without removing them from the DOM, which helps preserve their state and improve application performance.

We recommend reading this article, in which developers share recommendations for choosing a front-end framework. It details key factors to consider when choosing, such as performance, community support, documentation, and scalability. Choosing the right framework will help optimize the development process and improve the result.

It is important to understand that the v-show directive in Vue.js does not conditionally render an element, unlike the v-if directive. Instead, v-show manages the display property, which means the element is always present in the DOM tree, occupying its proper place, and its display depends on the value of the isShow variable.

In React, which is also a declarative framework, the syntax is less burdened with unnecessary elements. Despite not requiring direct interaction with HTML elements, React allows for a reactive relationship between data and display by encapsulating a significant amount of logic. Conditional rendering in React is implemented using the ternary operator, and iteration over elements is accomplished using the map function. This approach makes code cleaner and more understandable for JavaScript developers. React's philosophy can be described as an effort to avoid overloading developers with unnecessary syntax.

Comparing Vue.js and React, one can notice that Vue.js offers a more declarative approach. Developers simply specify how the display should look, while Vue automatically handles many details, including array iteration methods and display property management through simple directives. Vue is also a reactive framework that monitors model changes and updates the view as needed, simplifying state management.

Vue is called a progressive framework because it can be used minimally, installing only the core library, or additional tools can be gradually added to create a full-fledged infrastructure. For example, Vue Router is used for routing, and Vuex or Pinia for state management. These libraries are integrated into the Vue.js ecosystem and are an integral part of it.

Overall, the Vue.js ecosystem appears to be very cohesive. Vue Router and Vuex (or Pinia) are important libraries to learn. Also worth considering are the Vue CLI for automating routine tasks and Nuxt, a framework for server-side rendering of Vue applications.

Almost any project can be implemented with Vue.js, which can also be built using React or Angular. All things being equal, none of these frameworks offers significant advantages over the others. However, React still holds a slight lead in mobile app development thanks to React Native, although Vue is actively working to improve its capabilities in this area.

Vue.js in Companies

Many foreign companies have chosen Vue.js as their primary front-end framework, including such well-known brands as GitLab, Alibaba, Nintendo, Upwork, Zoom, Sony, and Grammarly. It is also worth noting that Russian companies such as Ozon and Sportmaster are actively implementing Vue.js in their projects. This framework attracts developers with its simplicity and flexibility, which ensures high performance and ease of development of modern web applications. Using Vue.js helps companies effectively adapt to rapidly changing market demands, improving the user experience and accelerating the development process.

Large tech companies have many internal projects, and the tech stacks of teams can vary significantly. While many IT giants, such as Apple and Google, use other front-end frameworks as their primary frameworks, they also utilize Vue.js. Mentions of Vue can be found in job postings by these companies, demonstrating its demand and flexibility in developing modern web applications.

A similar situation is observed at Yandex: React is actively used in most projects, while Vue is used only in isolated cases, such as Edadile. This demonstrates the popularity of React as a universal solution for developing web applications, while Vue finds its application in specific tasks and projects.

The Vue.js motto is "easy to learn, hard to master." I had the opportunity to participate in the Route256 school dedicated to Vue.js, organized by Ozon. Ozon uses a variety of methods when developing with Vue.js. For example, their developers emphasize performance, using functional components with render functions and deactivated reactivity, as well as a JSX syntax similar to that used in React. However, even within Ozon, approaches can vary significantly from team to team. Therefore, despite its apparent simplicity and low entry barrier, Vue.js has significant depth and can be adapted for lower-level development. This makes Vue.js a suitable choice for both novice and experienced developers seeking to optimize and improve the performance of their applications.

Vue.js Popularity

According to Stack Overflow research, Vue.js ranks among the top web frameworks in 2021. This confirms its widespread use and recognition among developers worldwide. Vue.js is easy to learn, flexible, and has a rich set of tools, making it an attractive choice for building modern web applications.

Infographic: Stack Overflow

React React remains a leader in the job market. In October 2021, the React framework was mentioned 7,636 times on the hh.ru platform, significantly exceeding Angular (3,649 times) and Vue.js (2,030 times). In April 2022, the situation remained similar: React was mentioned 4,921 times, Angular 2,139 times, and Vue.js 2,320 times. Analyzing the period from October 2021 to April 2022, it can be noted that the only framework whose mentions in job postings increased was Vue.js. At the same time, React and Angular have seen a decline in employer interest. This demonstrates the dynamics and changes in the preferences of developers and companies focusing on current technologies.

Conclusion

Comparing Vue.js and React is inevitable, as both technologies have a similar philosophy but differ in key aspects. The main differences between Vue.js and React are as follows: Vue.js offers simpler integration and ease of learning, while React provides more flexible options for creating complex user interfaces. Both frameworks are actively used for developing modern web applications, and the choice between them often depends on the specific requirements of the project and the preferences of the developer.

  • Vue is more strict and declarative. The rigor is evident in the syntax (specific directives for each task) and in the way the components themselves are built (a clear structure for separating model, view, and styles, especially when using single-file components with the .vue extension).
  • Vue has a more robust infrastructure—the choice of the most important libraries is often predetermined.

This approach allows beginners to easily write readable code from the very first steps of learning Vue.js. The given example shows that Vue code can be created without prior knowledge of ternary operators or array iteration methods. To do this, it is enough to master a few simple directives, such as v-for and v-show. Vue takes care of the rest of the tasks, simplifying the development process and making it more accessible for beginners.

In my opinion, all things being equal, the likelihood of making a mistake in Vue.js is lower, and its code is easier to understand. It is important to note that Vue has the same flexibility in expression as React. By delving deeper into the documentation, you can go beyond the standard framework, making Vue.js just as adaptable as React. The larger and more complex the project, the more likely it is that you'll need to learn advanced techniques with Vue.js and its tools. This makes Vue.js an excellent choice for both small and large-scale applications.

Documentation isn't always an easy source for learning programming tools. However, this is not the case with Vue.js. Even using only the official Vue.js documentation, you can achieve good results in learning the framework. However, additional resources, such as online courses and tutorial videos, can significantly facilitate understanding certain aspects of Vue and help deepen your knowledge. Using a variety of materials promotes a more complete understanding of the framework and allows developers to effectively apply it to their projects.

The main emphasis should be on regular practice. To effectively learn Vue, you need to solve a variety of problems, delve into the documentation, and experiment with different methods. Continuously increasing the complexity of projects will help strengthen your skills and deepen your understanding of the framework.

Reading is an important part of our lives, and it offers numerous benefits. It develops thinking, improves vocabulary, and deepens our understanding of the world around us. Reading books, articles, and other materials not only enriches our knowledge but also promotes emotional development. Research shows that regular reading helps reduce stress and improves concentration. It's important to choose a variety of genres and topics to broaden your horizons and gain new experiences. To maximize the benefits of reading, set aside time each day to immerse yourself in engaging stories and useful information. Read more to grow and develop.

  • JavaScript: the main tool for frontend developers
  • Easter algorithms: how mechanical computers are made to calculate Orthodox dates
  • Ganna Novikova aka Hannah Montana: "I came to DevOps because I deleted the product"