VueJs - Getting Started

Subscribe to my newsletter and never miss my upcoming articles

β€œTo get started with Vue, all you need is familiarity with HTML and JavaScript. With these basic skills, you can start building non-trivial applications within less than a day”- VueJs Docs

Hi vue and welcome to VueJs, The Series πŸš€


In this first episode we are going to cover the following topics:

  1. Getting Vue In Our Machine.
  2. Setting Up Our Environment.
  3. Conclusion

Getting Vue In Our Machine

We have a few different ways to install vue as you can see here but for the purpose of this tutorial I'll be using CDN.

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

Don't use this CDN for production.

Setting Up Our Environment

We will need an index.html and app.js files.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <!-- VueJs Import -->
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    <title>VueJs - Getting Started</title>
</head>
<body>
    <div id="app">
        <h1>{{ title }}</h1>
    </div>

    <script src="app.js"></script>
</body>
</html>

Your index.html should look like this ☝

  1. Imported VueJs CDN.
  2. Created a div with an id of app.
  3. Inside app created a title.

Let's go over 2 and 3 for a second:

  • The div will be under control of the Vue instance.
  • Title uses the special syntax that Vue will recognize and interpolate from our Vue instance.

Your app.js should look like this πŸ‘‡

new Vue({
  el: "#app",
  data: {
    title: "Hello World!"
  }
})

Hold your πŸ‡πŸ‡, WHAT?

We created our Vue instance with new Vue() that takes an object as an argument.

Then we have the el and data properties. All properties (there are more and we will see them in this series) have reserved names that Vue will recognize.

In the el property we need to pass the html element that we want the Vue instance to take control.

In the data property we store all the data we want to use in our Vue instance. Think of the properties store inside the data object as variables, you can have strings, booleans, arrays... In our case the data property is the string Hello world, very creative right?

Ok, so let's open our html file and see what we got there.

Alt Text

Congratulations, we created our first VueJs app! πŸŽ‰πŸ₯³

Conclusion

In this episode we covered the following:

  1. We installed the VueJs framework using CDN.
  2. We created our html template and use the special {{ }} syntax.
  3. We created our Vue instance and explain about the el and data properties.

TODO: Build this Hello World app by your own but this time instead of using a CDN, installing Vue in a different way.

Here is again the link for the other installation options.

GitHub repo for the code used in this episode.


Did you enjoy this article? Don't be selfish, go on and share the knowledge!

You can also find me on Twitter @eligarlo.

Comments (2)

Hillel's photo

Great tutorial, simple and easy. Keep them coming!

Eliahu Garcia Lozano's photo

Thanks Hillel, stay tuned!