element plus vue3中回车enter键 点击button

写法

element plus或者说vue3已经废弃了.naive的写法,在vue3中需要新写监听器

根据资料:https://blog.csdn.net/cqlcqlcui123/article/details/130141190,可以这样实现,只不过资料是composition风格的API,如果想要用选项式API(vue2那种),可以有如下:

export default {
    methods: {
            enter_up(e){
                console.log('in enter up')
                if (e.keyCode == 13 || e.keyCode == 100) {
                    console.log('success')
                }
            },
    },
    mounted(){
        window.addEventListener('keydown', this.enter_up)
    },
    unmounted(){
        window.removeEventListener('keydown', this.enter_up, false)
    }
}


enter success

补充

vue3的API风格:

你可能感兴趣的:(vue.js前端)