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 : 5065  
 
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

A Java approach: condtional structures

Hello everyone and welcome back! The previous times we have introduced the concept of variable, trying to define some basic concepts about it.  However, some situations suggest that the concept of…

Hashmap: hashing, collisions and first functions

Today we are going to study some concepts closely related to hashmaps. The concepts we are going to see are hashing and collisions. Hashing The idea of hashing with chaining is to…

Hashmap: Overflow Lists

In this short series of articles we will go to see how it is possible to create the Hashmap data structure in C. In the implementation we're going to use the…

Javascript: what are callbacks and how to use them.

Today we are going to learn about a concept that is widely used in javascript and that is used quite a lot by today's frameworks, libraries, especially NodeJS. This is…

A Java approach: variables - use case

Hello all friends and welcome back! After the introduction made on the variables, we try to analyse some critical issues that may arise in quite common situations. Let's start by analysing…

A Java approach: variables

Hello everyone and welcome back! Today we will begin a journey that will lead us to study, and possibly review, what are the basics of programming. We will start by talking…

HTTP Cookies: how they work and how to use them

Today we are going to write about the way to store data in a browser, why websites use cookies and how they work in detail. Continue reading to find out how…

The package managers npm and yarn: main differences

Npm and yarn are package managers that help to manage a project’s dependencies. A dependency is, as it sounds, something that a project depends on, a piece of code that…

The Javascript asign() method to merge and clone objects

In this article, we will be covering Object.assign()method in javascript in detail with examples. A javascript object is a collection of key-value pairs. Keys are also known as properties of object. Keys…

All the javascript functions and methods to manipulate arrays

This article will show that the prominent JavaScript array functions are .map(), .filter(), and .reduce(), and will then go through examples of instances in which .every() and .some() would save…

TypeScript: The evolution of JavaScript

When you're involved in the development of a large project, programming languages like JavaScript don't seem to be the best solution. Their lack of elements such as Language Aids has…

Awesome JavaScript Games and Js Software to create Games

Best sites js13kGames 2019 - Highlights from the js13kGames 2019 competition. js13kGames 2018 - 13 Games in ≤ 13kB of JavaScript. js13kGames 2017 - Build a game in 13kB or less with js13kGames. Adventure Triangle:…