Articles

What is a Single Page Application and what is Vue.js

Vue.js is a progressive and open source JavaScript framework used to develop interactive web user interfaces and single page applications.

Vue.js mainly focuses on the visualization part of the application, also called front-end development. Vue.js is getting popular day by day because it's very easy to integrate with other projects and libraries. It is very simple to install and use.

What is Vue.js?

Vue.js is a progressive JavaScript framework open source used for developing interactive web user interfaces and single page applications (SPAs). Vue.js is commonly referred to as Vue and pronounced as "view.js" or "view".

What is a Single Page Application (SPA)?

A Single Page Application or SPA is a web application or website that provides users with a very smooth, responsive and fast experience similar to a desktop application. A single page application contains a menu, buttons and blocks on a single page. When a user clicks on one of them, it dynamically rewrites the current page rather than loading whole new pages from a server. This is the reason behind its responsive speed.

Vue is basically built for frontend development, so it has to handle a lot of HTML, JavaScript and CSS files. Vue.js makes it easy for users to extend HTML with HTML attributes called directives. Vue.js provides built-in directives and many directives definite by the user to improve the functionality of HTML applications.

Features of Vue.js

Below is the list of the most important features of Vue.js:

Components

Vue.js components are one of the important features of this framework. They are used to extend basic HTML elements to encapsulate reusable code. You can create reusable custom elements in Vue.js applications that can later be reused in HTML.

templates

Vue.js provides HTML-based templates that can be used to associate the rendered DOM with Vue instance data. All Vue templates are valid HTML that can be parsed by spec-compliant browsers and HTML parsers. Vue.js compiles models into Virtual DOM rendering functions. Vue renders components into virtual DOM memory before refreshing the browser. Vue can also calculate the minimum number of components to re-render and apply the minimum amount of DOM manipulation when changing application state.

Reactivity

Vue provides a responsiveness system that uses simple JavaScript objects and optimizes re-rendering. In this process, each component keeps track of its reactive dependencies, so the system knows exactly when and which components to re-render.

Routing

Page navigation is done with the help of vue-router. You can use the officially supported vue-router library for your single page application.

Transitions

Vue allows you to use different transition effects when elements are inserted, updated or removed from the DOM.

How to install Vue.js ?

There are several methods to use Vue.js. You can install it by going to its official site or you can start using the Vue.js file from the CDN library as well. Here are some ways to use Vue.js in your project.

Directly in the HTML file

If you want to use the tag <script> of Vue.js directly into your HTML file, you need to download it from the official website.

<html>  
   <head>  
      <script type = "text/javascript" src = "vue.min.js"></script>  
   </head>  
   <body>
   </body>  
</html>  

Let's go to the Vue.js official website https://vuejs.org/v2/guide/installation.html to download vue.js according to your needs.

Using CDN

You can also use the Vue.js file from CDN, in your application. Use the link https://unpkg.com/vue@3/dist/vue.global.js inside the element <script>, as below:

<script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>

Benefits of using Vue.js

Vue.js is one of the latest software technologies widely used for web development and building Single Page Applications (SPA). As you can guess from the name, it is mostly used for UI or display side of the project.

Let's see the benefits of using Vue.js in your project:

Very small size

One of the biggest advantages of Vue.js is that it is very small in size. The success of a JavaScript framework depends a lot on its size and this exciting JavaScript plugin is only 18-21KB, so you can very easily download and use it in no time.

Innovation newsletter
Don't miss the most important news on innovation. Sign up to receive them by email.
Easy to understand and code

The Vue.js framework has a very simple structure and is very easy to understand. It is one of the reasons for the popularity of this framework. If you are familiar with HTML and JavaScript, you can easily code in Vue.js. Users can easily add Vue.js to their web project due to its simple structure and develop applications.

Simple integration with existing applications

Vue.js has many components for everything and can be integrated very quickly with existing applications. You can integrate it with any application written in JavaScript.

Flexible by nature

The flexible nature of Vue.js also makes it easy for developers of React.js, Angular.js, and any other new JavaScript frameworks to understand. It provides a lot of flexibility to use virtual nodes to write HTML files, JavaScript files and pure JavaScript files.

Components

You can create custom elements that are reusable in Vue.js applications.

Simple, complete and detailed documentation

Vue.js provides very simple, complete and detailed documentation, so developers who have little idea about HTML and JavaScript can use it to program.

virtual DOM

Vue.js uses virtual DOM similar to other existing frameworks like ReactJS, Ember, etc. The virtual DOM is a lightweight in-memory tree representation of the original HTML DOM and is updated without affecting the initial DOM.

Two-way communication

Vue.js provides two-way communication with its Model View View Model (MVVM) architecture that simplifies the handling of HTML blocks.

Vue.js declarative rendering

The framework comes with a system that allows us to declaratively render data to the DOM using simple and straightforward model syntax.

Here is an example:

<body>
<div id="app">  
  {{ message }}  
</div>

<script>
var app = new Vue({  
  el: '#app',  
  data: {  
    message: 'This is a simple Vue.js Declarative Rendering example!'  
  }  
})  
</script>
</body>

The Vue.js framework allows us to definire HTML attributes called directives, which are used to provide functionality to HTML applications.

There are two types of directives in Vue.js:

  • integrated directives e
  • directives definished by the user.

Vue.js uses double braces {{}} as placeholders for data, and Vue.js directives are HTML attributes that use a v- prefix.

A Vue app connects to a single DOM element and fully controls it. In the above example, it's #app.

With Vue we can consider the HTML as the entry point, and everything else happens inside the created Vue instance.
Let's see an example where we try element and attribute binding:

<html>  
    <head>  
        <link rel="stylesheet" href="index.css">  
        <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>  
    </head>  
    <body>         
        <div id="app-2">  
        <span v-bind:title="message">  
            Hover mouse over me for a few seconds  
            and see a dynamically bound title which I have set!  
        </span>  
        </div>          
        <script>
           var app2 = new Vue({  
           el: '#app-2',  
           data: {  
           message: 'You loaded this page on ' + new Date().toLocaleString()  
                 }  
           })  
       </script>  
    </body>  
</html>  

In this case, the new v-bind attribute is the directive. Directives are used with a v- prefix to indicate that they are unique attributes provided by Vue, and are used to apply special responsive behavior to the rendered DOM.

The result of the example is the following

Ercole Palmeri

Innovation newsletter
Don't miss the most important news on innovation. Sign up to receive them by email.

Latest Articles

UK antitrust regulator raises BigTech alarm over GenAI

The UK CMA has issued a warning about Big Tech's behavior in the artificial intelligence market. There…

April 18 2024

Casa Green: energy revolution for a sustainable future in Italy

The "Green Houses" Decree, formulated by the European Union to enhance the energy efficiency of buildings, has concluded its legislative process with…

April 18 2024

Ecommerce in Italy at +27% according to the new Report by Casaleggio Associati

Casaleggio Associati's annual report on Ecommerce in Italy presented. Report entitled “AI-Commerce: the frontiers of Ecommerce with Artificial Intelligence”.…

April 17 2024

Brilliant Idea: Bandalux presents Airpure®, the curtain that purifies the air

Result of constant technological innovation and commitment to the environment and people's well-being. Bandalux presents Airpure®, a tent…

April 12 2024