Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Vue.js: Understanding its Tools and Ecosystem

You're reading from   Vue.js: Understanding its Tools and Ecosystem Take a crash course in the main concepts and syntax of the Vue.js library

Arrow left icon
Product type Paperback
Published in Nov 2019
Publisher
ISBN-13 9781800206625
Length 194 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Authors (2):
Arrow left icon
Dave Berning Dave Berning
Author Profile Icon Dave Berning
Dave Berning
Backstop Media LLC Backstop Media LLC
Author Profile Icon Backstop Media LLC
Backstop Media LLC
Arrow right icon
View More author details
Toc

Table of Contents (11) Chapters Close

Preface
1. Getting Started with Vue.js 2. Scaffolding Projects With Vue CLI 3 FREE CHAPTER 3. Navigation with Vue Router 4. State Management with Vuex 5. Debugging With Vue DevTools 6. Server-Side Rendering with Nuxt.js 7. Static Site Generation with VuePress 8. Mobile App Development with NativeScript for Vue.js 9. Greater Control of JavaScript and Type Casting with TypeScript 10. The Future of Vue.js and Adoption Rates

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.

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime