[Vue] Setup custom keyCode

Vue provide some shortcut methods:

  • @mousemove.stop is comparable to e.stopPropogation()
  • @mousemove.prevent this is like e.preventDefault()
  • @submit.prevent this will no longer reload the page on submission
  • @click.once not to be confused with v-once, this click eventwill be triggered once.
  • v-model.lazy won’t populate the content automatically, it will wait to bind until an event happens.

You can define your own shortcut methods as well: doc

Vue.config.keyCodes = {
  v: 86,
  f1: 112,
  // camelCase won`t work
  mediaPlayPause: 179,
// instead you can use kebab-case with double quotation marks
  "media-play-pause": 179,
  up: [38, 87]
}

<input type="text" @keyup.media-play-pause="method">

猜你喜欢

转载自www.cnblogs.com/Answer1215/p/9418795.html