This repository constitutes to all the implementations, learnings, exercises built through the course by Maximilian Schwarzmüller
- First Vue App
- Vue Js DOM
- Vue Conditionals
- Rendering Lists
- Using Vue CLI
- Introduction to the Components
- Communication between the Components
- Handling forms
- Vue Directives
- Vue Filters
- Vue Mixins
Building the the first ever Vue application is quite simple. Follow the following steps
" rel="nofollow">https://cdn.jsdelivr.net/npm/vue/dist/vue.js">A new Vue instance needs to be created for handling the application, templating, binding etc. It can be created by the following syntax
new Vue({
...
...
...
});
Declarative Rendering
To connect the data and DOM i.e. control the template from the vue application there are some properties to be given to our Vue instance
1. El property
el property is like the query selector which is used to select the template with in the Vue application.
new Vue({
el: "#app",
});
2. Data property
data property holds the data, that needs to be passed to the template
new Vue({
el: "#app",
data: {
title: "Hello World!",
},
});
We can use the above title field any where in the template with the following syntax
(Data binding)
<div id="app">
<p>{{title}}p>
div>
Now, the data and DOM are linked, try changing the data which asynchronously changed the DOM element with the updated data.
Suppose we want to add an input field and make the value of title field to the value entered in the input field. It's kinda two way data-binding, and can be done by using the v-on vue directive. Attributes to that directive can be added by using the : and the attribute(event) name, in this case input is the event. It's value is a method which would be triggered once the event is fired.
<input type="text" v-on:input="changeTitle" />
new Vue({
el: "#app",
data: {
title: "Hello World!",
},
methods: {
changeTitle: function (event) {
this.title = event.target.value;
},
},
});
Using the above code, the title data would be the same as the value entered in the input field (Two-way data binding)
Here all the concepts related to the following are covered
- Binding data
- Binding attributes
- V-once directive
- V-html directive
- Events
- Passing our own arguments to events
- Event modifiers
- Two way data binding
- Dependant properties
- Dynamic Styling
In modern applications only at a particular time, few views needs to be shown based on the data returned from the back-end. In Vue, v-if directive is here to save us serving its purpose of conditional rendering. It operates on the truthy and falsy values i.e. if truthy show that particular element, falsy detaches the whole element from the DOM including the nested elements.
<p v-if="show">Do you also see me?p>
new Vue({
el: "#app",
data: {
show: true,
},
});
Like the v-if there is also the v-else directive which executes if the v-if returns the falsy value. It is inherited from the parent if condition, i.e. cannot stand independantly.
<p v-else>Do you also see me?p>
In the latest vue versions of >2 there is one more directive serving the purpose of else-if conditions
<div v-if="type === 'A'">Adiv> <div v-else-if="type === 'B'">Bdiv> <div v-else-if="type === 'C'">Cdiv> <div v-else>Not A/B/Cdiv>