First Step to Learning Vue JS - 3
Display Hello World and custom message using two-way data binding

I am a Front end developer currently working on React JS, HTML, CSS, Python, Vue JS, Webpack, Babel, AEM etc.
Search for a command to run...
Display Hello World and custom message using two-way data binding

I am a Front end developer currently working on React JS, HTML, CSS, Python, Vue JS, Webpack, Babel, AEM etc.
I'm glad I run through your article Kritika Pattalam Bharathkumar. I'm actually thinking to start learning VueJs myself. I had taken some courses in the past but I have to admit I don't remember a lot... 😊 This weekend I might start again!
Hope this helped to jog your memory of what you learned before. 😊
This series talks about Tips & Tricks and simple projects you can build using JavaScript. Click on the articles below to read more.
Build a random quote generator using an API - JavaScript
Are you planning to start your coding journey?. Then this is for you - a roadmap to help you achieve your goals.

7 ways in which you can add files to your commit using git add

As a website user, one would have come across links or buttons which say "Click to download" or "Download" on a website. Have you ever wondered how can you add one to your website?. Keep reading!!!. As part of this blog let us see how one can crea...

Build a random quote generator using an API - JavaScript

Kritika Pattalam Bharathkumar | Web Developer - The official blog of Kritika Pattalam Bharathkumar
22 posts
Front End Engineer | Writes about HTML, CSS, JavaScript and everything related to web development | Follow me on Twitter let's chat.
As part of this blog, let's see how to get started with Vue JS -3. Just like any other tech stack, the first step is to print a hello world, as much as anyone can say that it is the easiest thing. But that first step can be overwhelming for anyone who is very new to programming. Hence this blog post.
There are 3 things that need to be done, in order to get our HTML running
The first step to starting with a Vue project is including the Vue package. As part of this simple project I am going to include the below script tag in the head section of the HTML. If you are planning to use it in production, probably would want to consider using versioned resources.
<script src="https://unpkg.com/vue@next"></script>
Include a div with the id "hello". This id will be used in our custom script and inside this is where you will display the message from the custom script
<div id="hello">
<h1> Display my message here</h1>
</div>
Create a file called script.js inside which we will write our script to display our static message, and this file should be included as the last thing in the body section. The main reason to include this as the last item is, the script gets included in the sequential order.
<body>
<div id="hello">
<h1> Display my message here</h1>
</div>
<script src="script.js"></script>
</body>
So let's assume if this script was added in the head section, what happens is, the Vue js package script first gets executed, and the next script to execute will be the script.js. Script.js has code that looks for the div with id=hello and it will throw an error. This is because, the div hello is added after the script in the body section, hence it will not be available yet for the script to push the custom message into that div.
Hence include the script.js as the last file in the body, so that the DOM is available when our custom script executes.
In the below script
## Final Script
const helloWorld = {
data() {
return {
message: "Hello World - This is Vue 3"
}
}
}
Vue.createApp(helloWorld).mount('#hello');
Now save the above script file and what do you see?. Nothing yet, you will still be seeing the h1 with the value "Display my message here" that is because we need to access the message in the HTML. This can be done using text interpolation. Replace the dummy message with {{message}}
<div id="hello">
<h1>{{ message }}</h1>
</div>
<!Doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Hello World Vue - 3</title>
<script src="https://unpkg.com/vue@next"></script>
</head>
<body>
<div id="hello">
<h1>{{ message }}</h1>
</div>
<script src="script.js"></script>
</body>
</html>
Now save the above Final HTML and Final Javascript, when you open the HTML in the browser you should be seeing the below output

Well, we saw how to display a static message, how about trying to get the input from the user and display that message instead.
I am going to include a v-model directive, which accepts input from the user, and as and when the user types, the message gets displayed on the page. This is called two-way data binding, this can be done by just updating the HTML as below
<div id="hello">
<h1>{{ message }}</h1>
<input type="text" v-model=message />
</div>
Follow me on Twitter | LinkedIn for more web development related tips and posts. Feedbacks and suggestions are welcome.
Checkout my other blog post series