mirror of
https://github.com/kevin-DL/build-gmail-clone-with-vue-3.git
synced 2026-01-15 12:24:45 +00:00
Abstract to useKeydown composition API
This commit is contained in:
17
src/composition/useKeydown.js
Normal file
17
src/composition/useKeydown.js
Normal file
@@ -0,0 +1,17 @@
|
||||
import { onBeforeUnmount } from 'vue';
|
||||
|
||||
export const useKeydown = function(keyCombo) {
|
||||
let onkey = function(event) {
|
||||
if(keyCombo.key == event.key) {
|
||||
keyCombo.fn()
|
||||
}
|
||||
}
|
||||
|
||||
window.addEventListener('keydown', onkey);
|
||||
|
||||
onBeforeUnmount(()=> {
|
||||
window.removeEventListener('keydown', onkey);
|
||||
})
|
||||
}
|
||||
|
||||
export default useKeydown;
|
||||
Reference in New Issue
Block a user