Book Image

Vue.js: Understanding its Tools and Ecosystem

By : Dave Berning
Book Image

Vue.js: Understanding its Tools and Ecosystem

By: Dave Berning

Overview of this book

Vue.js is one of the top three “go-to” JavaScript frameworks and is used by organizations such as Nintendo, NASA, and Expedia. This book is primarily focused on the ecosystem of Vue.js and its development tools. Understanding the basics of the technology behind the Vue.js ecosystem will improve your skills and make you a better problem solver. The book begins with a brief overview of Vue.js. You’ll learn to work your way through the Vue command line interface CLI 3, and use the Vue Router library to navigate between the different views of your application. As you advance through the topics, you’ll explore the use of DevTools to improve the quality of your applications and how to implement server-side rendering in your application through the Nuxt.js framework. Toward the end of the book, you’ll read about the future of Vue.js and its growing popularity. After reading this book, you’ll be able to create industry-grade applications using Vue.js and its tools.
Table of Contents (11 chapters)

Key Modifiers

Not only can you listen for an event, but you can also listen for specific keys that have been pressed. Again, you can do this is Vanilla JavaScript, but Vue.js makes this a whole lot easier. These key modifiers allow you to specify which key event you want a function to run. For example, if you want to run a function when the enter key is pressed and released, just use @keyup.enter.

<button @keyup.enter="someFunction">Button Text</button>

Other pre-defined key modifiers include:

  • tab
  • delete (both delete and backspace)
  • esc
  • space
  • up
  • down
  • left
  • right

If you wish to run a function when a specific key is pressed, you will need to obtain the key code of that specific key. There are a lot of resources out there for you to get the key code. If you don’t want to look through a long list of codes, you can visit Keycode.Info and get the key code by pressing the key you want to listen to.

For example, if you want to listen to the shift key, you can add a keyup modifier to listen to the keycode, 16.

<button @keyup.16="someFunction">Button Text</button>

One last thing about keyup events. You can even register or map a specific key to an event. You can do so easily with:

Vue.directive('on').keyCodes.f1 = 112;

This custom event will register the F1 key to @keyup.f1. The f1 of the registration is a friendly name and can be anything that is meaningful to you.