Is it possible to set a v-on:keyup.enter
on the whole page, not only for an input element in javascript framework Vue.js ?
相关问题
- Axios OPTIONS instead of POST Request. Express Res
- Vue.js - set slot content programmatically
- Getting Uncaught TypeError: …default is not a cons
- Vue.js computed property loses its reactivity when
- How to remove the Vuetify append-icon from the seq
相关文章
- Best way to dynamically change theme of my Vue.js
- vue-router how to persist navbar?
- How to Properly Use Vue Router beforeRouteEnter or
- Difference between nameFunction() {} and nameFunct
- Vue - best way to reuse methods
- setTimeout() not working called from vueJS method
- How to unbind an array copy in Vue.js
- Vue Cli 3 Local fonts not loading
Short answer is yes, but how depends on your context. If you are using vue-router as I am on a current project, you would want to add to the outer-most element you want that applied to. In my case I'm using the actual app.vue entry point's initial div element.
There is one catch that I believe is a hard requirement, the element has to be within the potentially focusable elements. The way I'm dealing with that is setting a -1 tabindex and just declaring my super-hotkeys (mostly for debug purposes right now) on the parent element in my app.
EDIT:
As a side note, I also added a touch of additional configuration to my vue-router to make sure the right element is focused when I transition pages. This allows the pageup/pagedown scrolling to already be in the right section based on the content area being the only scrollable section. You'd also have to add the tabindex="-1" to the app-content element as well.
and the basis of my app-content component:
Perhaps a better way to do this is with a Vue component. This would allow you to control when you listened to events by including or not including the component. This would also allow you to attach event listeners to Nuxt using the no-ssr component.
Here is how you create the component:
Then on the page you want to use that component you'd add this HTML:
And then you'll have to add your event handler method: