Vue.js: a quick start guide for beginners. Part 1.

by Janeth Kent Date: 10-12-2019 javascript vueJs tutorial guide


Learning a new framework can be a very complicated process for any developer, especially for someone that is still learning the basics of JavaScript. For this reason, we decided to create this series, which will make Vue.js learning as easy and digestible as possible.

How to integrate Vue.js to your project

There are several ways you can integrate Vue into your web project. Let's begin with the simplest one.

Most tutorials automatically assume that you understand how to set up and run a development environment in which you should use things like npm, the webpack...

We will start with a much simpler beginner-friendly approach.

Just go ahead and run your favorite code editor. Then, create a new file called index.html.

<html>
  <head>
     <title>Vue test page</title>
  </head>
  <body>
     <h1>Hi world!</h1>
     <div id="app"></div>
  </body>
</html>

We just set the bones for a simple website, nothing really fancy. Now, let's get the library of Vue. Before closing,< /body > paste this script tag.

[...]    
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>  
</body>

So we can use Vue now that it's loaded into our page. Let's go ahead and and and in a < script > tag create a new Vue instance. We will give it a selector by passing #app to the options object property, and Vue will know where to render our app.

Place this script after html.

<script>      
const app = new Vue({          
    el: '#app', // 1          
    data: { // 2             
       myLocalProperty: 'Im a local property value' // 3          
    }      
 });  
</script>

So what's going on here? We created a Vue instance and pass It a configuration object.

  1. el: As I said before,  we have to tell Vue where we want our app to be displayed in our HTML. Div with the app ID in this ca
  2. data object: Vue instance has a local storage system, such as a box of variables and properties that we can use when coding the app. Data holds a JavaScript object, so we assign it one with the { } syntax. Inside, we place a property.
  3. myLocalProperty: This property is defined within the data object for our instance, the name is myLocalProperty and the value on the right is the value - a string in this case.

Displaying properties on our app

Right now, if you open index.html in your browser, there's not much going on.

Let's add some code:

<html>      
<head>          
<title>Vue 101</title>      
</head>        
<body>          
 <h1>Hi world!</h1>         
 <div id="app">            
 <p>My local property: {{ myLocalProperty }}</p>          
</div>            
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>            
<script>            
   const app = new Vue({              
     el: '#app',              
     data: {                
     myLocalProperty: 'Im a local property value'              
     }            
   });          
</script>

Be careful with this line:

<p>My local property: {{ myLocalProperty }}</p>

What's happening here is called variable interpolation, which is a fancy term for "I'm going to display the content of my myLocalProperty variable in this placeholder where my {{ }} are now.

Reload the page, and you will now see the string updates to reflect our variable.

Go ahead and try to change the string inside myLocalProperty to some other text and reload the page, you should see the text update accordingly.

Vue is a reactive framework

Let's discuss reactivity. You may have heard that Vue is a reactive framework. But what exactly does this mean? Open up your console in the chrome developer tools, and with your index.html loaded type:

app.myLocalProperty = 'Vue is reactive';

You will see the page react to this change!

Read Vue.js: a quick start guide for beginners. Part 2!

 
by Janeth Kent Date: 10-12-2019 javascript vueJs tutorial guide hits : 5646  
 
Janeth Kent

Janeth Kent

Licenciada en Bellas Artes y programadora por pasión. Cuando tengo un rato retoco fotos, edito vídeos y diseño cosas. El resto del tiempo escribo en MA-NO WEB DESIGN END DEVELOPMENT.

 
 
 

Related Posts

What are React Hooks and what problems they solve

Working with React, - and before the release of Hooks in version 16.8 -  there was always the possibility to create components in three different ways based on a number of…

Flattening arrays in JavaScript

When we are handling arrays that are arrays or have multiple dimensions it can be very useful to know how to flatten arrays in JavaScript. That is to say, to…

How to populate an array with random numbers in JavaScript

Some of you might think that what we explained in the article on how to populate an array with numbers, apart from the didactic part, would not have much applicability…

How to populate an array with numbers in JavaScript

Populate an array with numbers in JavaScript The first step is to initialise the array. So today we are going to see a simple way to do it and see how…

Top Javascript Libraries and Frameworks Part 2

What are JavaScript frameworks?   JavaScript frameworks are application frameworks that allow developers to manipulate code to meet their particular needs. Web application development is like building a house. You have the option…

How to Send Email from an HTML Contact Form

In today’s article we will write about how to make a working form that upon hitting that submit button will be functional and send the email (to you as a…

Top JavaScript libraries and frameworks part 1

JavaScript libraries and frameworks make it easy to develop websites and applications with a wide variety of features and functionality, all with dynamic, flexible and engaging features. According to a 2020…

Looping through a matrix with JavaScript

We were already talking about how to multiply arrays in JavaScript and we realised that we had not explained something as simple as traversing an array with Javascript. So we…

How to multiply matrices in JavaScript

It may seem strange to want to know how to multiply matrices in JavaScript. But we will see some examples where it is useful to know how to perform this…

JavaScript Formatting Date Tips

Something that seems simple as the treatment of dates can become complex if we don't take into account how to treat them when presenting them to the user. That is…

How to make a multilingual website without redirect

Today, we're going to talk about how to implement a simple language selector on the basic static website, without the need of any backend or database calls or redirection to…

Starting with Bootstrap-Vue step by step

Today we will show you how to use BootstrapVue, describe the installation process and show basic functionality. The project’s based on the world's most popular CSS framework - Bootstrap, for building…

We use our own and third-party cookies to improve our services, compile statistical information and analyze your browsing habits. This allows us to personalize the content we offer and to show you advertisements related to your preferences. By clicking "Accept all" you agree to the storage of cookies on your device to improve website navigation, analyse traffic and assist our marketing activities. You can also select "System Cookies Only" to accept only the cookies required for the website to function, or you can select the cookies you wish to activate by clicking on "settings".

Accept All Only sistem cookies Configuration