Skip to Content

Getting Started with VueJS: A Hello World Tutorial

Building a VueJS web application is simple. So simple in fact, this will probably be one of the shortest tutorials I've written so far. Let's dive in!

Hello World Example

We're going to create a basic Hello World example because it's what you do when first starting out in a new development environment.

First, let's create our div element with a message variable placeholder:

<div id="app">
{{message}}
</div>

This creates a declarative rendering, meaning it will allow us to render data to the DOM using simplistic template syntax.

Next, let's include the latest version of the VueJS library:

<script src="https://unpkg.com/vue@next"></script>
For development and testing purposes, including the VueJS library like this is fine. I highly recommend downloading the latest version and creating a local copy on your server for production environments. This will ensure that any changes made to the library will not negatively affect your web application.

Now, let's add the functionality:

const HelloWorld = {
data() {
return {
message: "Hello World!"
}
}
};

Vue.createApp(HelloWorld).mount("#app");

This creates a link between the data and the DOM, where the true magic happens! Here, we're creating an object uniquely called HelloWorld which creates a data() property that then returns the value of our message variable, Hello World!.

Once our data object is created, we can then initalize our Vue web application and mount the HelloWorld object to our div element we created in the first step. This will now link the {{message}} variable placeholder to the variable created in our object.

Conclusion

Phew! Getting started, that may be a lot to take in. But, once you get going with Vue, you'll find the beauty in its simplicity with even the most complex of tasks.

Last Updated: August 21, 2022
Created: July 05, 2021

Comments

There are no comments yet. Start the conversation!

Add A Comment

Comment Etiquette: Wrap code in a <code> and </code>. Please keep comments on-topic, do not post spam, keep the conversation constructive, and be nice to each other.