Skip to content

Instantly share code, notes, and snippets.

@christopheragnus
Created October 29, 2018 14:01
Show Gist options
  • Save christopheragnus/4a3f2633db0436e7750fbd6ecf43e73b to your computer and use it in GitHub Desktop.
Save christopheragnus/4a3f2633db0436e7750fbd6ecf43e73b to your computer and use it in GitHub Desktop.
Vuejs Actions / Events
// Calls addToCart method on component:
<button v-on:click="addToCart">
// Shorthand
<button @click="addToCart">
// Arguments can be passed:
<button @click="addToCart(product)">
// To prevent default behaviour eg. page reload
<form @submit.prevent="addProduct">
// Only trigger once:
<img @mouseover.once="showImage">
//Stop all event prpagation
.stop
// Only trigger if event.target is element itself
.self
// Keyboard entry example
<input @keyup.enter="submit">
// Call onCopy when control-c is pressed:
<input @keyup.ctrl.c="onCopy">
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment