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 language.

First, let's create our div element with a message 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@3.4.27/dist/vue.global.js"></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 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:

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

Vue.createApp(HelloWorld).mount("#app");
</script>

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 returns the value of our message variable, Hello World!.

Once our data object is created, we can initalize our Vue 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

You've taken your first steps into a whole new world! Once you get going with Vue, you'll find the beauty in its simplicity with even the most complex of tasks.

Last Updated: May 20, 2024
Created: July 05, 2021