Module2-events Flashcards
<p>How do you react to an event in html in Vue</p>
<p>You need to use the v-on:click for example to respond to the click event and connect it to a method in the methods section v-on:click="handleClick"</p>
a short hand instead of v-on=”click” is @click
<p>Should v-on:event point to ="add()" or ="add"?</p>
<p>Both syntax work. If there are no params you usually use the later syntax but you need the parenthesis version if you want to pass values to the function</p>
What is the default argument provided by js to an event handler
JS provide the event handler with an object that describes the event itself as an argument.
<p>how do you get access to the element that the event occurred on?</p>
<p>once you get the default event object you can use event.target to receive the element that the event was triggered on.</p>
<p>How do you keep the behavior of getting the default event object?</p>
<p>You keep the default behavior by not calling the method with () but just pointing to the method name.</p>
<p>how do you get the value of an element that an event occurred on?</p>
<p>You connect the element and event by using v-on. you point the v-on to the name of the method you want to invoke so you don't override the default behavior of getting the event object. once you get the event object you need to call event.target.value to get the value.</p>
<p>how do we send the event object to the method if we want to pass an additional parameter (ex. last name)?</p>
<p>In order to send the event object and another value to a method in the event handler we need to use the following syntax: v-on:click="add($event,lastName);</p>
<p>how do you prevent a form from doing its default behavior of submit when we click a button in the form?</p>
<p>we can call a method on v-on:submit and then use the event object to call event.preventDefault(); OR
<br></br>We can use an event modifier on the event like v-on=submit.prevent</p>
What are buttons event modifiers for
.left .middle .right (don’t need the .left since this is the default behavior)
What are keys event modifiers
<p>.tab <br>.delete <br>.esc <br>.space <br>.up <br>.down <br>.left <br>.right <br>.ctrl <br>.alt <br>.shift <br>.meta</p>
How do you make an event fire just once
use the .once event modifier
<p>how do you stop an event from propagating</p>
<p>use event.stop event modifier</p>
<p>how to Only trigger if event.target is element itself</p>
<p>use the event.self event modifier</p>
<p>what does v-once do?</p>
<p>v-once is a directive that tells vue to evaluate the data binding only once .</p>
<p>what does v-model directive do</p>
<p>v-model creates a 2 way binding. it replaces the need to write the following (if myField is the binded field to the input) v-bind:value=,v-on="input "=</p>