mirror of
https://github.com/kevin-DL/build-gmail-clone-with-vue-3.git
synced 2026-01-23 15:41:33 +00:00
Close modal with escape key
This commit is contained in:
@@ -9,6 +9,21 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
export default {
|
export default {
|
||||||
|
mounted: function () {
|
||||||
|
window.addEventListener('keydown', this.onkey)
|
||||||
|
},
|
||||||
|
beforeUnmount: function () {
|
||||||
|
window.removeEventListener('keydown', this.onkey)
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
onkey(event){
|
||||||
|
if(!this.isOpened) { return null }
|
||||||
|
|
||||||
|
if(event.key == 'Escape') {
|
||||||
|
this.closeModal()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
props: {
|
props: {
|
||||||
isOpened: {
|
isOpened: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
|
|||||||
Reference in New Issue
Block a user