自学内容网 自学内容网

【Vue】特殊的按键修饰符 tab、ctrl、meta(win键)、alt

当我们在input框中按tab键想触发事件时,发现失去焦点并不会触发事件。

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <script type="text/javascript" src="js/vue.js"></script>
</head>
<body>
    <!-- 准备好一个容器 -->
    <div id="root">
        <input type="text" placeholder="按下回车提示输入" @keyup.tab="showInfo">
    </div>

    <script>
        // 创建Vue实例
        new Vue({
            el: '#root',
            data: {
                msg: 'Vue2'
            },
            methods: {
                showInfo() {
                    alert("我是Vue2");
                }
            }
        })
    </script>
</body>
</html>

应该修改为:

@keydown.tab="showInfo"

其余ctrl、meta(win键)、alt同理。


原文地址:https://blog.csdn.net/qq_38196449/article/details/142715909

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!