Tutorial

Hello World in Vue.js

Published on August 25, 2016
author

Alligator.io

Hello World in Vue.js

Vue.js is quickly becoming a very popular option as a library for reactive components. It’s lightweight, simple to grasp and fun to play with, and it can prove to be a great alternative to other libraries like React or Angular.

Let’s get our feet wet with the simplest of examples. Here’s the code for our basic Hello World app, with the interesting parts highlighted:

<!DOCTYPE html>
<html lang="en">
  <meta>
    <meta charset="UTF-8">
    <title>Hello World in Vue.js</title>
  </meta>

  <body>
	
    <div id="hello-world-app">
      <h1>{{ msg }}</h1>
    </div>

    <script
      src="//cdnjs.cloudflare.com/ajax/libs/vue/2.1.6/vue.min.js">
    </script>

    <script>
      new Vue({
        el: "#hello-world-app",
        data() {
          return {
            msg: "Hello World!"
          }
        }
      });
    </script>

  </body>
</html>

Step by step breakdown:

  • First we have a basic HTML boilerplate file.
  • A div with an id of #hello-world-app will contain our app.
  • In the div, we have an h1 and a reference to an msg piece of data.
  • We call for the minified Vue.js library that’s hosted on cdnjs. 2.1.6 is the latest version as of this writing.
  • We then instantiate a new Vue object and tell it with el that our app is the #hello-world-app div.
  • Finally, we provide the data needed with the data object. In this case, we provide the data for msg.

And that’s it for this brief introduction! Learn more by reading the getting started section of the official Vue.js guide.

Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.

Learn more about our products

About the authors
Default avatar
Alligator.io

author

While we believe that this content benefits our community, we have not yet thoroughly reviewed it. If you have any suggestions for improvements, please let us know by clicking the “report an issue“ button at the bottom of the tutorial.

Still looking for an answer?

Ask a questionSearch for more help

Was this helpful?
 
Leave a comment


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Join the Tech Talk
Success! Thank you! Please check your email for further details.

Please complete your information!

Featured on Community

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more