1

写法

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)
    }
}


<el-button type="primary" @keydown.enter="enter_up()">enter success</el-button>

补充

vue3的API风格:


Yonggie
95 声望4 粉丝