千峰商城-springboot项目搭建-29-vue按键修饰符
按键修饰符就是针对键盘事件的修饰符。限定哪个按键会触发事件。
@keyup.enter:只有点击回车键的时候会触发。
enter、tab、delete、esc、space、up、down、left、right.
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> <link rel="stylesheet" href="css/bootstrap.css" /> <script type="text/javascript" src="js/jquery-1.7.2.min.js"></script> <script type="text/javascript" src="js/bootstrap.js"></script> <script type="text/javascript" src="js/vue.js"></script> </head> <body> <div id="container"> <form action="https://www.baidu.com"> <!--.prevent:消除元素的默认操作--> <button type="submit" class="btn btn-success btn-xs" @click.prevent="test">测试</button> </form> <div style="width: 200px;height: 200px; background: red;" @click.self="method1"> <div style="width: 150px;height: 150px; background: green;" @click="method2"> <button type="button" @click.stop="method3">测试</button> </div> </div> <input type="text" @keyup.enter="method4" /> </div> <script type="text/javascript"> var vm = new Vue({ el:"#container", data:{ }, methods:{ test:function(event){ console.log("-------test") }, method1:function(){ alert("1"); }, method2:function(){ alert("2"); }, method3:function(){ alert("3"); }, method4:function(){ alert("4"); } } }); </script> </body> </html>
除了vue提供的按钮别名外,我们还可以根据键盘为按键自定义别名。
Vue.config.keyCodes.aaa = 74
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> <link rel="stylesheet" href="css/bootstrap.css" /> <script type="text/javascript" src="js/jquery-1.7.2.min.js"></script> <script type="text/javascript" src="js/bootstrap.js"></script> <script type="text/javascript" src="js/vue.js"></script> </head> <body> <div id="container"> <form action="https://www.baidu.com"> <!--.prevent:消除元素的默认操作--> <button type="submit" class="btn btn-success btn-xs" @click.prevent="test">测试</button> </form> <div style="width: 200px;height: 200px; background: red;" @click.self="method1"> <div style="width: 150px;height: 150px; background: green;" @click="method2"> <button type="button" @click.stop="method3">测试</button> </div> </div> <input type="text" @keyup.aaa="method4" /> </div> <script type="text/javascript"> //给键74起个别名 Vue.config.keyCodes.aaa = 74 var vm = new Vue({ el:"#container", data:{ }, methods:{ test:function(event){ console.log("-------test") }, method1:function(){ alert("1"); }, method2:function(){ alert("2"); }, method3:function(){ alert("3"); }, method4:function(){ alert("4"); } } }); </script> </body> </html>
分类:
千峰商城项目
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· PowerShell开发游戏 · 打蜜蜂
· 在鹅厂做java开发是什么体验
· 百万级群聊的设计实践
· WPF到Web的无缝过渡:英雄联盟客户端的OpenSilver迁移实战
· 永远不要相信用户的输入:从 SQL 注入攻防看输入验证的重要性