We now have a youtube channel. Subscribe!

Vue.js | Introduction

Vue.js Introduction


Hello folks! welcome back to a new edition of our Vue.js tutorial. In this tutorial, we will be studying about Vue.js Introduction.

Vue.js is a JavaScript framework for building web user interfaces. Its core part is focused mainly on the view layer and it's very easy to understand. The version of Vue that we are going to use for this tutorial is 2.0.

As Vue is basically built for development of front-end web interfaces, we will deal with a lot of HTML, JavaScript and CSS files in our subsequent tutorial posts. To have a proper understanding of the details, let's begin with a simple example.

In this example, we'll use the development version of vue.js.

Example

<html>
   <head>
      <title>VueJs Introduction</title>
      <script type = "text/javascript" src = "js/vue.js"></script>
   </head>
   <body>
      <div id = "intro" style = "text-align:center;">
         <h1>{{ message }}</h1>
      </div>
      <script type = "text/javascript">
         var vue_det = new Vue({
            el: '#intro',
            data: {
               message: 'My first VueJS Task'
            }
         });
      </script>
   </body>
</html>

Output

When the above example is executed, it will produce the following result -


This is the first app we've created via Vue.js. As seen in the above example, we've added Vue.js at the beginning of the .html file.

<script type = "text/javascript" src = "js/vue.js"></script>


There is a div which is included in the body that prints "My first VueJS Task" in the web browser.

<div id = "intro" style = "text-align:center;">
   <h1>{{ message }}</h1>
</div>

We've included a message in a interpolation, i.e. {{}}. This interacts with Vue.js and prints the data in the browser. To get the value of the message in the DOM, we're creating an instance of Vue.js as follows -

var vue_det = new Vue({
   el: '#intro',
   data: {
      message: 'My first VueJS Task'
   }
})

In the above code snippet, we're calling the Vue instance, which takes the id of the DOM elements i.e. e1:'#intro', it is the id of the div. There is a data with message assigned the value 'My first VueJS Task'. Vue.js interacts with Dom and changes the value in the Dom {{message}} with 'My first VueJS Task'.

If we happened to change the value of the message in the console, the same is going to be reflected in the browser. For example -


Console Details


In the above console, we have printed the vue_det object, which is an instance of Vue. We're updating the message with 'VueJs is interesting' and the same is changed in the browser instantly as seen in the screenshot above.

This is just a basic example that shows the linking of Vue.js with DOM, and how we can manipulate it. In our up coming tutorials, we will learn about directives, conditional loops, components, etc.


Alright guys! This is where we are going to be rounding up for this tutorial. In our next tutorial, we will be discussing about Vue.js Instances.

Feel free to ask your questions where necessary and we will attend to them as soon as possible. If this tutorial was helpful to you, you can use the share button to share this tutorial.

Follow us on our various social media platforms to stay updated with our latest tutorials. You can also subscribe to our newsletter in order to get our tutorials delivered directly to your emails.

Thanks for reading and bye for now.

Post a Comment

Hello dear readers! Please kindly try your best to make sure your comments comply with our comment policy guidelines. You can visit our comment policy page to view these guidelines which are clearly stated. Thank you.
© 2022 ‧ WebDesignTutorialz. All rights reserved. Developed by Jago Desain