DEV Community

Cover image for VueJs - Getting Started
Eliahu Garcia Lozano
Eliahu Garcia Lozano

Posted on • Edited on

VueJs - Getting Started

This article was first posted on my blog, here is the article


β€œ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 will be covering the following topics:

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>
Enter fullscreen mode Exit fullscreen mode

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>
Enter fullscreen mode Exit fullscreen mode

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!"
  }
})
Enter fullscreen mode Exit fullscreen mode

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, install Vue in a different way.

Here is again the link for the other installation options.

GitHub repo for the code used in this episode.


Find me on Twitter @eligarlo

Top comments (0)