Skip to content

vue组件中如何给div绑定keydown等键盘事件 #8981

@sdlddr

Description

@sdlddr

What problem does this feature solve?

我需要给一个DIV绑定keydown事件,可是我在组件中对该DIV加了tabindex="0"属性后,依然无法成功使用addEventListener方法或者div.onkeydown=function(){……}的方式成功绑定。这是不是VUE的一个BUG?
如果是纯JS原生环境下,对DIV加入tabindex="0"属性,是可以绑定键盘事件的。
例子:

<div style="width:100px;height:100px;background:#000" @keydown="renderKeydown($event)">

……
renderKeydown(e){
console.log('e.keyCode', e.keyCode);
},
////结果连'e.keyCode'字样都没有输出。

What does the proposed API look like?

能在VUE下成功的对DIV,SPAN等元素绑定键盘事件。

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions