mirror of
https://github.com/kevin-DL/build-gmail-clone-with-vue-3.git
synced 2026-01-15 20:34:47 +00:00
Put modal esc key in setup function
This commit is contained in:
@@ -8,20 +8,20 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { onMounted, onBeforeUnmount } from 'vue';
|
||||
export default {
|
||||
mounted: function () {
|
||||
window.addEventListener('keydown', this.onkey)
|
||||
},
|
||||
beforeUnmount: function () {
|
||||
window.removeEventListener('keydown', this.onkey)
|
||||
},
|
||||
methods: {
|
||||
onkey(event){
|
||||
|
||||
setup({closeModal}, context){
|
||||
let onkey = function(event){
|
||||
if(event.key == 'Escape') {
|
||||
this.closeModal()
|
||||
closeModal()
|
||||
}
|
||||
}
|
||||
onMounted(()=> {
|
||||
window.addEventListener('keydown', onkey);
|
||||
})
|
||||
onBeforeUnmount(()=> {
|
||||
window.removeEventListener('keydown', onkey);
|
||||
})
|
||||
},
|
||||
props: {
|
||||
closeModal: {
|
||||
|
||||
Reference in New Issue
Block a user