VueJS is one of the easiest frameworks to pick up very quick. I started learning web development 10 years ago and I had to struggle with DOM directly, later on learned JQuery to help with the interaction with DOM, but it was always a tedious task to accomplish. VueJS come with so many features that made it both fun and easy, focusing on the production and developer experience. In this article We will explore together all key aspects of this amazing framework.
This is the basic VueJs application you can build. Make sure to add vuejs cdn link and voila, you got your first vuejs application.
<div id="app">
<p>{{ message }}</p>
</div>
<script>
var app = new Vue({
el: '#app',
data: {
message: 'Welcome to the Vue.js magic show!'
}
});
</script>
Picture this: You have a magic wand (Vue.js) that connects your data with what users see on the screen. When your data changes, the screen updates automatically, just like magic! It is also known as two-way data binding.
<template>
<button @click="increment">{{ count }}</button>
</template>
<script>
export default {
data() {
return {
count: 0
};
},
methods: {
increment() {
this.count++;
}
}
};
</script>
Think of Vue.js components as LEGO bricks. You can mix and match them to create anything you want, from a simple house to a towering castle! Each component is like a separate piece that does its own thing, making it easy to build big things without getting overwhelmed. The reusability in vuejs is made easy with the help of components and SFC(aka single file components), where you can write html code, style it and make it dynamic with a js script, all in one component.
Imagine you have a magic book (Virtual DOM) that shows you how to make changes to your web page without actually touching it. This makes things super fast because you’re not constantly rearranging everything. It’s like having a genie who can rearrange your room without lifting a finger!
Directives in Vue.js are like simple instructions you give to your web page. Want something to appear or disappear? Just tell Vue.js with a special command, and it’s done! It’s like having a helpful assistant who can make things happen with a wave of your hand.
<div v-if="isVisible">Now you see me</div>
<button @click="toggleVisibility">Toggle Visibility</button>
<script>
export default {
data() {
return {
isVisible: true
};
},
methods: {
toggleVisibility() {
this.isVisible = !this.isVisible;
}
}
};
</script>
Think of computed properties and watchers as your personal assistants who keep track of things for you. They help you calculate stuff or keep an eye on changes so you don’t have to worry about it. It’s like having a friend who always remembers your favorite ice cream flavor!
Vue Router is like a map for your web app. It helps users navigate from one place to another without getting lost. Whether they’re exploring a new page or going back to where they started, Vue Router makes sure they always know where they are.
Vuex is like a big closet where you keep all your stuff organized. Instead of scattering your data all over the place, Vuex helps you keep everything neat and tidy in one central location. It’s like having a magical organizer who knows exactly where everything belongs!
In Vue.js, every component has special moments called lifecycle hooks. These are like checkpoints where you can do certain things, like setting things up when a component is created or cleaning up when it’s destroyed. It is very important to have such functions in order to track and implement business logic in different circumstances.
Vue CLI is like a magical toolbox filled with everything you need to build awesome web apps. Need to start a new project? Just use Vue CLI to set everything up for you! It’s like having a handy toolkit that does all the hard work so you can focus on building real stuff.
In essence, Vue.js is like a fun ride where you get to experience wonderful things with ease. With its key features as your guide, you’ll land on a journey filled with excitement and discovery. So dive in, and experience the magic of Vue.js!