Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why VueJs introduce .native Event modifier ? What are the use case of this? - Vue.js

Tags:

vue.js

vuejs2

I din't get any docs for native event modifiers. I have seen some where like this:

<router-link @click.native="pressThis()"> Press here </router-link>

what is the use of native modifier on router-link click event. and what other use case native modifier can have ?

like image 802
Mukund Kumar Avatar asked Dec 09 '17 14:12

Mukund Kumar


People also ask

What is event modifiers in Vue JS?

Vue provides event modifiers for v-on by calling directive postfixes denoted by a dot. .stop. .prevent. .capture. .self.

Why We Use $V in Vue JS?

$v is an object that calls vuelidate (at the time of writing the comment, supported in version Vue. js 2.0), which is intended to check every input, which is made in a non-html form.

What is the use of Vue JS?

Vue (pronounced /vjuː/, like view) is a JavaScript framework for building user interfaces. It builds on top of standard HTML, CSS and JavaScript, and provides a declarative and component-based programming model that helps you efficiently develop user interfaces, be it simple or complex.

What event modifier is used for performing the Click event only for one time?

once Event Modifier. It allows the event to execute only once. Syntax: <button v-on:click.


1 Answers

You can override Vue events in custom components. For instance, you might have a list component that once you click an item you call this.$emit('click', selectedItemData), and that will emit the click event to the parent component that is watching that.

However, sometimes you really want to bind to the native HTML/DOM event listener element.addEventListener('click', callThisMethod), and that's the use of .native. Also, make a note that it will handle cleaning the event listener once your component gets destroyed just like a non-native event.

In sum: use .native when you need the 'raw' event from DOM.

like image 52
Ivan Seidel Avatar answered Oct 05 '22 13:10

Ivan Seidel