Vue.js is an open-source Model–View–ViewModel front-end JavaScript framework for building user interfaces and single-page applications. Vue.js has many own directives for DOM manipulation such as v-bind, v-on, v-model, etc. In this article, we will see how to handle the events and their Implementations.
Event Handling: An event handler is a function with an explicit name and a piece of code will be executed when it’s triggered. If a button was clicked or an input was changed by user actions. This kind of action is called an Event. Events provide a dynamic interface for web applications, these events are hooked to HTML elements in Document Object Model (DOM). When an event occurs, DOM listens to the event and responds accordingly to event handlers. Events are used to listen to the actions in DOM and run some JavaScript code when they are triggered. We can use the v-on directive for handling events in Vue.js.
Syntax:
<element v-on:click="handlerName"></element>
Alternatively, we can use @ symbol as a shortcut. Use @ instead of using the v-on directive:
<element @click="handlerName"></element>
Some of the v-on mouse events are commonly used for Event handling, i.e., @click, @mouseover, @mouseout, @mouseleave. For instance, Buttons are used to trigger events & it is one of the HTML components used for Event handling. When we click the button it will execute the events for DOM manipulation.
<button v-on:click="firstBtn">Click me</button>
DOM listens to events and handling with JavaScript functions through Vue components
methods: {
// Function triggered when cursor click the button
firstBtn : function() {
alert('mouse clicked now');
}
}
There are 3 ways to design an Event handler:
- Inline handlers
- Method handlers
- Method handlers with custom arguments
The following Vue.js directives are used below the Event handler:
- v-model: This directive is used to create two-way data bindings on form input, text area, etc.
- v-bind: This directive is used to manipulate HTML attributes, change the style, and assign classes with help of binding.
- v-if and v-else: This directive is used for conditional rendering.
- v-on: This directive is used to the DOM elements to listen to the events.
Inline handlers: Inline handlers are typically used in simple use cases where we need to execute a single statement.
Document Object Model (DOM) listens for events in Vue.js by passing inline code.
Syntax:
<button v-on:click='n++'>
Button clicked {{n}} times
</button>
Here, n is the data model object initialized by Vue Component. Initially, its value is 0, When you click the button it will increment and show ‘Button clicked n times’.
Example 1: In the below example, we are using Inline handlers for Button. Create an input text box and add the v-model directive to bind the two-way data flow. when we enter a text inside the text box it will display the same using the v-model directive. If we move the cursor mouse over to the hide button then it will hide the input text and show a text as ‘contents are hidden’ and when leaving the mouse cursor from the button it will show the contents typed in the text box.
HTML
<template>
<h1>Inline Handler</h1>
<input v-model="name"
placeholder="Type Text Here" />
<button v-on:mouseover="active = !active"
v-on:mouseout="active = !active"
v-bind:style="{ width: '70px',
height: '30px' }">
Hide
</button>
<h1 v-if="active">
{{ name }}
</h1>
<h1 v-else>
Contents are Hidden
</h1>
</template>
<script>
export default {
name: "app",
data() {
return {
name: "",
active: true,
};
},
};
</script>
<style>
h1 {
color: green;
}
</style>
Output:
Example 2: In the below example, we are designing Inline handlers for Buttons. Create an input text box and add the v-model directive to bind the two-way data flow. when we enter a text inside the text box it will display the same using the v-model directive. When we click the [+] button it will increase the font size of the text and use the [-] button to decrease it. Inline event handlers are used for buttons to increase and decrease the text size. When we click the third button, it will trigger the inline handlers and each time the button value changes according to the number of clicks.
HTML
<template>
<h1>
Geeks For Geeks
</h1>
<button v-on:click='sizeOfFont++'>
+
</button>
<input v-model='sampleText'
placeholder='Type Text Here' />
<button v-on:click="sizeOfFont--">
-
</button>
<br><br>
<button v-on:click='n++'>
Button clicked {{n}} times
</button>
<!--Binding styles dynamically for
sample text( using v-bind directive )-->
<h4 v-bind:style="{fontSize: sizeOfFont + 'px' }">
{{sampleText}}
</h4>
</template>
<script>
export default {
name: "App",
data() {
return {
n: 0,
sampleText: '',
sizeOfFont: 20
};
}
};
</script>
<style>
h1 {
color: green;
}
</style>
Output:
Method Handlers: Method handlers are typically used in complex cases. This is used to handle the events with a set of statements. In Vue.js a property name or value string points to a method defined on the Vue components. Method handlers are triggered through function calls.
Syntax: Add a string value or property name in v-on:click event:
<button v-on:click="wish">
Wish Me
</button>
here, wish is a JavaScript function as a property event for the button, when clicking the button it will trigger the function and alert the given message:
methods: {
wish : function() {
alert('Happy Birthday')
}
}
Example 3: In the below example, we are using Method handlers. Create an input text box and add the v-model directive to bind the two-way data flow. when we enter a text inside the text box it will display the same using the v-model directive. When we click the button it will reset the text field. If we move the mouse cursor over to the RESET button then the text box will turn a yellow color and leaving the mouse cursor from the button text box will turn into the original color.
HTML
<template>
<h1>Method handlers</h1>
<input v-model='sampleText'
placeholder='Type Text Here'
v-bind:style="colorStyle" />
<button v-on:click="resetInput"
v-on:mouseover="mouseIn"
v-on:mouseleave="mouseOut">
Reset
</button>
<h1>{{sampleText}}</h1>
</template>
<script>
export default {
name: "App",
data() {
return {
sampleText: '',
// Button style binding with help v-bind directive
colorStyle: {
backgroundColor: "white"
}
};
},
methods: {
// Method that triggered by mouse click
// event and clear the text box
resetInput : function() {
this.sampleText = '';
},
// Method that triggered by mouse over event
// and change the color into yellow
mouseIn : function() {
this.colorStyle.backgroundColor = "yellow";
},
// Method that triggered by mouse leave event
// and change the color into white
mouseOut : function() {
this.colorStyle.backgroundColor = "white";
}
}
};
</script>
<style>
h1 {
color:green;
}
</style>
Output:
Method handlers with custom arguments: This approach is similar to method handlers. Instead of binding directly to a method name, we can also call methods with custom arguments. It is used to pass the method with custom arguments instead of the native event.
Syntax: Add a property name in v-on:click event and pass arguments through the property name.
<button v-on:click="wish('happy birthday')">
Wish Me
</button>
Here, we have bonded the javascript function as a property event for the button, when clicking the button it will trigger the function and alert the message that custom arguments passed through the function call.
methods: {
wish : function(msg) {
alert(msg)
}
}
Example 4: In the below example, we are designing Method handlers with custom arguments. Create an input text box and add the v-model directive to bind the two-way data flow. when we enter a text inside the text box it will display the same using the v-model directive. When we click the button, DOM will listen to the event and pass the text as an argument to methods. The method will trigger the Property Changes to User Interface and display an alert message with entered Text. If we move the cursor mouse over to SUBMIT button then the text box will turn a yellow color and leaving the mouse cursor from the button text box will turn into the original color. When the cursor over/leaves the button another method will trigger the property changes to button color based on the color passed as argument.
HTML
<template>
<input v-model="sampleText"
placeholder='Type name Here' />
<button v-on:click="warn(sampleText)"
v-bind:style="colorStyle"
v-on:mouseover="mouseInOut('yellow')"
v-on:mouseleave="mouseInOut('white')">
Submit
</button>
<h1>
{{sampleText}}
</h1>
</template>
<script>
export default {
name: "App",
data() {
return {
sampleText: '',
// Button style binding with help v-bind directive
colorStyle: {
backgroundColor: "white"
}
};
},
methods: {
// Method that triggered by mouse click
// event and alert Welcome message along
// with typed text in text box
warn : function(text) {
alert(' ENTERED TEXT : ' + text );
},
// Method that triggered by mouse over/mouse
// leave event and change the color based on
// parameters passed through function call
mouseInOut : function(color) {
this.colorStyle.backgroundColor = color;
}
}
};
</script>
Output:
Event Modifiers: It is used to handle the events DOM itself, we don’t need to write any code to trigger it. For example, the event.preventDefault() is used to prevent the browser’s default behavior. Instead of writing this, we can bind it with the v-on directive in Vue.js.
Syntax:
<button v-on:click.prevent="firstbtn">
Submit
</button>
The following modifiers are available in Vue.js.
- .prevent: Prevents default behavior
- .stop: Prevents event bubbling up the DOM tree
- .capture: Capture mode is used for event handling
- .self: Only trigger if the target of the event is itself
- .once: Run the function at most once
- .passive: Improving performance on mobile devices(.prevent and .passive shouldn’t be used together in one element).
Key Modifiers: It is used to handle the keyboard events When DOM listening. It is similar to event modifiers when we enter a particular key. Key modifiers will listen and trigger according to the key. Keyup is the keyword used with v-on directive for keyboard-related events. We can directly use any valid key names on the suffix of keyup ( like keyup.keyname ).
Syntax:
<input v-on:keyup.enter="myFunction" />
The following key modifiers are available in Vue.js:
- .enter: It captures enter key
- .tab: It captures the tab key
- .delete: It captures both “Delete” and “Backspace” keys
- .esc: It captures the escape key
- .space: It captures the space bar key
- .up: It captures the up arrow key
- .down: It captures the down arrow key
- .left: It captures the left arrow key
- .right: It captures the right arrow key
Event System Modifier Keys: It is used to trigger keyboard event listeners only when the corresponding System modifier key is pressed. System Modifier keys refer to keys such as control, shift, and alter.
Syntax: Use the keyup event on a text input as we did before in key modifiers, this time used with the shift/alter/control and enter modifiers.
<input v-on:keyup.shift.enter = "func1" /> // Press Shift + Enter
Multiple Event Handlers: We can use multiple events in an event handler. It helps multiple handlers in v-on directive to bind event listeners for DOM events.
Syntax:
<button v-on:click="func1,func2">
Submit
</button>
Or
<button v-on:click="func1"
v-on:mouseleave="func2">
Submit
</button>
Create the JavaScript functions for the event property associated with the buttons, When we click the button it will trigger both functions and update the changes in DOM according to the events.
methods: {
func1: function() {
// first function handler logic here...
},
func2: function() {
// second function handler logic here...
}
}
HTML Listeners: Listeners are used to Handling events that help add interactivity to web applications by responding to the user’s input. Vue.js allows us to handle events triggered by the user. It provides us with the v-on directive to handle these events.
Example 5: In the below example, we created multiple event handlers for the input field. It will use multiple event handlers associated with Key modifiers if the user press any particular key then the key modifier will trigger the changes in DOM.
HTML
<template>
<h1>
Key Modifiers
</h1>
<input v-on:keyup.enter="key1"
v-on:keyup.esc="key2"
v-on:keyup.space="key3"
v-on:keyup.delete="key4" />
<h3>
{{sampleText}}
</h3>
</template>
<script>
export default {
name: "App",
data() {
return {
sampleText:''
};
},
methods: {
key1: function() {
this.sampleText =
'Now you pressed the Enter key'
},
key2: function() {
this.sampleText =
'Now you pressed the Escape key'
},
key3: function() {
this.sampleText =
'Now you pressed the Space key'
},
key4: function() {
this.sampleText =
'Now you pressed the Delete or Backspace key'
}
}
};
</script>
<style>
h1 {
color:green;
}
</style>
Output :
Example 6: In the below example, we created multiple event handlers for the input field. it will use multiple event handlers associated with System modifier keys. If the user presses any particular key with specific system modifier keys, then it will trigger the changes in DOM.
HTML
<template>
<h1>
System Modifier Keys
</h1>
<input v-on:keyup.alt.enter='key1'
v-on:keyup.shift.up='key2'
v-on:keyup.ctrl.a='key3' />
<h3>
{{sampleText}}
</h3>
</template>
<script>
export default {
name: "App",
data() {
return {
sampleText:''
};
},
methods: {
key1: function() {
this.sampleText =
'Now you pressed the Alt + Enter key'
},
key2: function() {
this.sampleText =
'Now you pressed the Shift + Up key'
},
key3: function() {
this.sampleText =
'Now you pressed the Ctrl + A key'
}
}
};
</script>
<style>
h1 {
color:green;
}
</style>
Output:
Similar Reads
Vue.js Tutorial
Vue.js is a progressive JavaScript framework for building user interfaces. It stands out for its simplicity, seamless integration with other libraries, and reactive data binding. Built on JavaScript for flexible and component-based development.Supports declarative rendering, reactivity, and two-way
4 min read
Basics
Vue.js Introduction & Installation
Vue JS is a JavaScript framework used to design and build user interfaces. It is one of the best frameworks for Single Page Web Applications. It is compatible with other libraries and extensions as well. In the development field, there may be so many issues that can not be solved by using a single l
2 min read
Vue.js Instances
A Vue.js application starts with a Vue instance. The instances object is the main object for our Vue App. It helps us to use Vue components in our application. A Vue instance uses the MVVM(Model-View-View-Model) pattern. The Vue constructor accepts a single JavaScript object called an options object
2 min read
Vue.js Watchers
A Watcher in Vue.js is a special feature that allows one to watch a component and perform specified actions when the value of the component changes. It is a more generic way to observe and react to data changes in the Vue instance. Watchers are the most useful when used to perform asynchronous opera
3 min read
Vue.js Methods
A Vue method is an object associated with the Vue instance. Functions are defined inside the methods object. Methods are useful when you need to perform some action with v-on directive on an element to handle events. Functions defined inside the methods object can be further called for performing ac
2 min read
Vue.js Event Modifiers
Vue.js is a progressive javascript framework for developing web user interfaces. It is a performant, approachable, and versatile framework. We can create Single Page Applications as well as Full Stack applications. It is built on top of HTML, CSS, and Javascript which makes it easier for developers
3 min read
Vue.js DOM tree
Vue.js is a javascript framework that is used in building static as well as dynamic webpages and User Interfaces. It offers many lucrative features for developers to use. For example, virtual DOM, component architecture, directives, templates, event binding, and many more. Document Object Model (DOM
4 min read
How to write and use for loop in Vue js ?
Vue.js is one of the best frameworks for JavaScript like ReactJS. The VueJS is used to design the user interface layer, it is easy to pick up for any developer. It is compatible with other libraries and extensions as well. If you want to create a single-page application then VueJS is the first choic
4 min read
Vue.js Two Way Binding Model
Vue.js is a progressive framework for building user interfaces. The core library is focused on the view layer only and is easy to pick up and integrate with other libraries. Vue is also perfectly capable of powering sophisticated Single-Page Applications in combination with modern tooling and suppor
2 min read
Vue.js Reusing Components
Vue.js is a progressive javascript framework for developing web user interfaces. It is a performant, approachable, and versatile framework. We can create Single Page Applications as well as Full Stack applications. It is built on top of HTML, CSS, and Javascript which makes it easier for developers
4 min read
Vue.js List Rendering
Vue.js is a progressive framework for building user interfaces. The core library is focused on the view layer only and is easy to pick up and integrate with other libraries. Vue is also perfectly capable of powering sophisticated Single-Page Applications in combination with modern tooling and suppor
4 min read
Vue.js List Rendering Mutation Methods
Vue.js is a progressive framework for building user interfaces. The core library is focused on the view layer only and is easy to pick up and integrate with other libraries. Vue is also perfectly capable of powering sophisticated Single-Page Applications in combination with modern tooling and suppor
3 min read
Vue.js v-cloak Directive
The v-cloak directive is a Vue.js directive that will remain on the element until the associated Vue instance finishes compilation. Combined with CSS rules such as [v-cloak] { display: none }, this directive can be used to hide uncompiled mustache bindings until the Vue instance is ready. First, we
1 min read
Vue.js Passing Data to Child Components with Props
Vue.js is a progressive javascript framework for developing web user interfaces. It is a performant, approachable, and versatile framework. We can create Single Page Applications as well as Full Stack applications. It is built on top of HTML, CSS, and Javascript which makes it easier for developers
3 min read
Vue.js Form Input Binding with Select option
Vue.js is a progressive javascript framework for developing web user interfaces. It is a performant, approachable, and versatile framework. We can create Single Page Applications as well as Full Stack applications. It is built on top of HTML, CSS, and Javascript which makes it easier for developers
3 min read
Vue.js Dynamic Components
Vue.js is a progressive javascript framework for developing web user interfaces. It is a performant, approachable, and versatile framework. We can create Single Page Applications as well as Full Stack applications. It is built on top of HTML, CSS, and Javascript which makes it easier for developers
3 min read
Vue.js Form Input Value Binding
Vue.js is a progressive javascript framework for developing web user interfaces. It is a performant, approachable, and versatile framework. We can create Single Page Applications as well as Full Stack applications. It is built on top of HTML, CSS, and Javascript which makes it easier for developers
5 min read
Vue.js Form Input Binding number Modifier
Vue.js is a progressive javascript framework for developing web user interfaces. It is a performant, approachable, and versatile framework. We can create Single Page Applications as well as Full Stack applications. It is built on top of HTML, CSS, and Javascript which makes it easier for developers
2 min read
Vue.js List Rendering v-for with v-if
Vue.js is one of the best frameworks for JavaScript like React JS. The Vue JS is used to design the user interface layer, it is easy to pick up for any developer. It is compatible with other libraries and extensions as well. In order to repeat a task for a fixed amount of time, we make use of the fo
3 min read
Vue.js List Rendering v-for with a Range
Vue.js is one of the best frameworks for JavaScript like React JS. The Vue JS is used to design the user interface layer, it is easy to pick up for any developer. It is compatible with other libraries and extensions as well. The Vue JS is supported by all popular browsers like Chrome, Firefox, IE, S
3 min read
Vue.js Form Input Binding with Checkbox option
Vue.js is a progressive javascript framework for developing web user interfaces. It is a versatile framework providing high speed and performance. We can create Single Page Applications as well as Full Stack applications. Input Binding is used to sync and maintain the state of form input elements wi
3 min read
Vue.js Form Input Binding with Multiline text
Vue.js is a progressive javascript framework for developing web user interfaces. It is a versatile framework providing high speed and performance. Â We can create Single Page Applications as well as Full Stack applications. Input Binding is used to sync and maintain the state of form input elements w
2 min read
Vue.js Form Input Binding trim Modifier
Vue.js is a progressive javascript framework for developing web user interfaces. It is a versatile framework providing high speed and performance. Â We can create Single Page Applications as well as Full Stack applications. Input Binding is used to sync and maintain the state of form input elements w
2 min read
Vue.js Form Input Binding with Radio Option
Vue.js is a progressive javascript framework for developing web user interfaces. It is a versatile framework providing high speed and performance. We can create Single Page Applications as well as Full Stack applications. Input Binding is used to sync and maintain the state of form input elements wi
3 min read
Vue.js List Rendering v-for with an Object
Vue.js is a progressive framework for building user interfaces. The core library is focused on the view layer only and is easy to pick up and integrate with other libraries. Vue is also perfectly capable of powering sophisticated Single-Page Applications in combination with modern tooling and suppor
3 min read
Vue.js Render Function with h() Arguments
Vue.js is a progressive javascript framework for developing web user interfaces. It is a performant, approachable, and versatile framework. We can create Single Page Applications as well as Full Stack applications. It is built on top of HTML, CSS, and Javascript which makes it easier for developers
3 min read
Vue.js Composition API with Templates
Vue.js is a progressive javascript framework for developing web user interfaces. It is a versatile framework providing high speed and performance. We can create Single Page Applications as well as Full Stack applications. The Composition API allows author to Vue components using imported functions r
3 min read
Vue.js Event Handling
Vue.js is an open-source ModelâViewâViewModel front-end JavaScript framework for building user interfaces and single-page applications. Vue.js has many own directives for DOM manipulation such as v-bind, v-on, v-model, etc. In this article, we will see how to handle the events and their Implementati
11 min read
Vue.js Declarative Rendering
Vue.js is a progressive framework for building user interfaces. The core library is focused on the view layer only and is easy to pick up and integrate with other libraries. Vue is also perfectly capable of powering sophisticated Single-Page Applications in combination with modern tooling and suppor
2 min read
Create a Hover effect in Vue.js
Vue is a progressive framework for building user interfaces. The core library is focused on the view layer only and is easy to pick up and integrate with other libraries. Vue is also perfectly capable of powering sophisticated Single-Page Applications in combination with modern tooling and supportin
1 min read
Types of data binding with template in Vue.js
In this article, we will see different ways to bind data with the template in Vue.js, along with understanding their implementation through the examples. When we wish to utilize our variables or data within the template, we generally use the mustache syntax(double curly braces). However, this isn't
8 min read
Vue.js Click Event
Vue.js is a progressive framework for building user interfaces. The core library is focused on the view layer only and is easy to pick up and integrate with other libraries. Vue is also perfectly capable of powering sophisticated Single-Page Applications in combination with modern tooling and suppor
2 min read
Pass data between components using Vue.js Event Bus
Component communication in Vue.js can become complicated and messy at times using $emit and props. In real-world applications where the Component tree is nested and big, it is not convenient to pass data using this method as it will only increase the complexity of the application and make debugging
3 min read
Vue.js Render Functions Component VNodes creation
Vue.js is a progressive javascript framework for developing web user interfaces. It is a performant, approachable, and versatile framework. We can create Single Page Applications as well as Full Stack applications. It is built on top of HTML, CSS, and Javascript which makes it easier for developers
2 min read
Vue.js List Entering & Leaving Transitions
Vue.js is a progressive javascript framework for developing web user interfaces. It is a versatile framework providing high speed and performance. Â We can create Single Page Applications as well as Full Stack applications. The Entering and Leaving Transitions are used to perform the animation on lis
3 min read
Vue.js Composition API using Provide
Vue.js is a progressive javascript framework for developing web user interfaces. It is a performant, approachable, and versatile framework. We can create Single Page Applications as well as Full Stack applications. It is built on top of HTML, CSS, and Javascript, making it easier for developers to i
3 min read
Vue.js List Move Transitions
Vue.js is a progressive JavaScript framework for developing web user interfaces. It is a versatile framework providing high speed and performance. We can create Single Page Applications as well as Full Stack applications. The Vue.js List Move Transitions smooths the transition when an element is add
3 min read
Vue.js Transitioning between the Components
Vue.js is a progressive javascript framework for developing web user interfaces. It is a performant, approachable, and versatile framework. We can create Single Page Applications as well as Full Stack applications. It is built on top of HTML, CSS, and Javascript which makes it easier for developers
3 min read
REST API Call to Get Location Details in Vue.js
In this article, we will know the REST API call to get the location details in VueJS, along with understanding its implementation through the examples. VueJS is one of the best frameworks for JavaScript like ReactJS. The VueJS is used to design the user interface layer, it is easy to pick up for any
7 min read
Directives
Vue.js Conditional Rendering
Vue.js is a progressive framework for building user interfaces. The core library is focused on the view layer only and is easy to pick up and integrate with other libraries. Vue is also perfectly capable of powering sophisticated Single-Page Applications in combination with modern tooling and suppor
2 min read
Vue.js List Rendering v-for with a Component
Vue.js is one of the best frameworks for JavaScript like ReactJS. The VueJS is used to design the user interface layer, it is easy to pick up for any developer. In order to repeat a task for a fixed amount of time, we make use of the for loop. The Components are used to build the combination of UI e
3 min read
Vue.js List Rendering v-for on a <template>
Vue.js is one of the best frameworks for JavaScript like React JS. The Vue JS is used to design the user interface layer, it is easy to pick up for any developer. It is compatible with other libraries and extensions as well. In order to repeat a task for a fixed amount of time, we make use of the fo
3 min read
Vue.js | v-if directive
The v-if directive is a Vue.js directive used to toggle the display CSS property of a element with a condition. If the condition is true it will make it visible else it will make it invisible. First, we will create a div element with id as app and let's apply the v-if directive to this element with
2 min read
Vue.js | v-text directive
The v-text directive is a Vue.js directive used to update a elementâs textContent with our data. It is just a nice alternative to Mustache syntax. First, we will create a div element with id as app and let's apply the v-text directive to this element with data as a message. Now we will create this m
1 min read
Vue.js | v-show directive
The v-show directive is a Vue.js directive used to toggle the display CSS property of a element with our data via inline styles. If the data is true it will make it visible else it will make it invisible. First, we will create a div element with id as app and let's apply the v-show directive to this
2 min read
Vue.js | v-html directive
The v-html directive is a Vue.js directive used to update a elementâs inner HTML with our data. This is what separates it from v-text which means while v-text accepts string and treats it as a string it will accept string and render it into HTML. First, we will create a div element with id as app an
2 min read
Vue.js v-on:click directive
The v-on:click directive is a Vue.js directive used to add a click event listener to an element. First, we will create a div element with id as app and let's apply the v-on:click directive to a element. Further, we can execute a function when click even occurs. Syntax:v-on:click="function"Parameters
1 min read
Vue.js v-once Directive
The v-once directive is a Vue.js directive that is used to avoid unwanted re-renders of an element. It treats the element as a static content after rendering it once for the first time. This improves performance as it does not have to be rendered again. First, we will create a div element with the i
1 min read
Vue.js v-on:click.ctrl Directive
The v-on:click.ctrl directive is a Vue.js directive used to add a click event listener to an element. While click directive triggers the event for all kinds of clicks, this directive only triggers the event when the ctrl key is pressed along with the click. First, we will create a div element with i
2 min read
Vue.js v-on:click.right Directive
The v-on:click.right directive is a Vue.js directive used to add a click event listener to an element. While click directive triggers the event for all kind of clicks, this directive only triggers the event when right key of mouse is clicked. First, we will create a div element with id as app and le
1 min read
Vue.js v-on:click.shift Directive
The v-on:click.shift directive is a Vue.js directive used to add a click event listener to an element. While click directive triggers the event for all kind of clicks, this directive only triggers the event when shift key is pressed along with the click. First, we will create a div element with id a
1 min read
Vue.js v-on:click.left Directive
The v-on:click.left directive is a Vue.js directive used to add a click event listener to an element. While click directive triggers the event for all kind of clicks, this directive only triggers the event when left key of mouse is clicked. First, we will create a div element with id as app and let'
1 min read
Vue.js v-on:click.alt Directive
The v-on:click.alt directive is a Vue.js directive used to add a click event listener to an element. While click directive triggers the event for all kind of clicks, this directive only triggers the event when alt key is pressed along with the click. First, we will create a div element with id as ap
1 min read
How a View-model works in Vue.js?
Vue.js is a front-end progressive javascript framework for building User Interfaces ( UI ) and Single Page Applications. This framework focuses on Model â View â ViewModel architecture pattern that connects the View ( User Interface ) and the Model ( Data Objects ). Vue.js uses many built-in directi
4 min read
v-on:click.middle Directive in Vue.js
v-on:click.middle directive is a Vue.js directive used to add a click event listener to an element. While click directive triggers the event for all kind of clicks, this directive only triggers the event when middle key of mouse is clicked. First, we will create a div element with id as app and let'
1 min read
Vue.js v-pre Directive
The v-pre directive is a Vue.js directive used to skip compilation for this element and all its children. You can use this for displaying raw mustache tags. First, we will create a div element with id as app and let's apply the v-pre directive to an element. Further, we can use a heading element to
1 min read
Vue.js Form Input Binding lazy Modifier
Vue.js is a progressive javascript framework for developing web user interfaces. It is a performant, approachable, and versatile framework. We can create Single Page Applications as well as Full Stack applications. It is built on top of HTML, CSS, and Javascript which makes it easier for developers
3 min read
Data Conversion to KB, MB, GB, TB using Vue.js filters
In this article, we are going to learn how to convert data to the given unit of data using filters in VueJS. Filters are a functionality provided by Vue components that let you apply formatting and transformations to any part of your template dynamic data. The filter property of the component is an
2 min read
Convert decimal point numbers to percentage using filters in Vue.js
Vue is a progressive framework for building user interfaces. The core library is focused on the view layer only and is easy to pick up and integrate with other libraries. Vue is also perfectly capable of powering sophisticated Single-Page Applications in combination with modern tooling and supportin
2 min read
Capitalizing a string using filters in VueJS
Vue.js is a progressive framework for building user interfaces. The core library is focused on the view layer only and is easy to pick up and integrate with other libraries. Vue is also perfectly capable of powering sophisticated Single-Page Applications in combination with modern tooling and suppor
2 min read
Vue.js Placeholder using filters
Vue.JS filters are a functionality provided by Vue components that let you apply formatting and transformations to any part of your template dynamic data. The filter property of the component is an object. A single filter is a function that accepts a value and returns another value. The returned val
3 min read
Truncate a String using filter in Vue.js
In this article, we are going to learn how to truncate strings using filters in VueJS. Filters are a functionality provided by Vue components that let you apply formatting and transformations to any part of your template dynamic data. The filter property of the component is an object. A single filte
2 min read
What is the difference between one-way data flow and two-way data binding in vue.js?
Vue.js is an open-source front-end JavaScript framework for building user interfaces and single-page applications. It follows Model-View-ViewModel (MVVM) architecture pattern. Vue.js has many in-built directives for DOM manipulation such as v-bind, v-on, v-model, etc. In this article, we will learn
7 min read