in Tutorials, Vue.js

Getting Started with Vue.js – Vue Instance

If you are someone like me who is struggling to type Vue and ends up typing View, don’t worry, you are in good company.

Getting started with Vue.js involves two simple things:

  1. Install Node.js from https://nodejs.org/en/
  2. That’s it.

In this first tutorial, we will see how to work with the Vue instance. Vue instance is nothing but creating an object for Vue which will then be able to take full advantage of all the functionality available in vue.

To get started, create a project folder for ex: vue-app. Inside this folder, create an index.html or any .html file with the following code. Do read the comments to understand why I wrote what I wrote.

<html>
	<head>
		<!-- just any other regular html tag -->
		<title>Vue Demo App</title>
		<!-- Fetch vue.js from the following library -->
		<!-- Other alternatives are to download the original library from https://vuejs.org/ -->		
		<script src="https://unpkg.com/vue"></script>
		<style>
			/*
			Some styling to make Hello World look better.
			 */
			#app {
			  font-family: 'Montserrat', Helvetica, Arial, sans-serif;
			  -webkit-font-smoothing: antialiased;
			  -moz-osx-font-smoothing: grayscale;
			  text-align: center;
			  color: #2c3e50;
			  margin: 20px;
			  font-size:26px;
			}
		</style>
	</head>
	<body>
		<!-- 
			Element to play around using vue. 
			"app" is used in the javascript written below to add text and perform relevant actions.
		-->
		<div id="app">
			{{text}}
		</div>
		<script>
			//app is assigned to the Vue instance. 
			//Vue accepts el and data to target the div. 
			var app = new Vue({
				el: "#app",
				data: {
					text: "Hello World!"
				}
			});
		</script>
	</body>
</html>

The above codes leads to the following output:

0