Vue键盘事件用法总结
更新时间:2017年04月18日 14:36:25 作者:阁下长的好生俊俏
本篇文章主要介绍了Vue键盘事件用法总结,详细的介绍了各种键盘事件的用法,有兴趣的可以了解一下
这两天学习了Vue.js 感觉组件这个地方知识点挺多的,而且很重要,所以,今天添加一点小笔记,学习一下Vue键盘事件
键盘事件
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<script src="../js/Vue.js" charset="utf-8"></script>
<script type="text/javascript">
window.onload = function () {
var vm = new Vue({
el: '#box',
data: {},
methods: {
show: function (ev) {
alert(ev.keyCode)
}
}
});
}
</script>
</head>
<body>
<div id="box">
<input type="text" @keydown="show($event)">
</div>
</body>
</html>
keyCode
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<script src="../js/Vue.js" charset="utf-8"></script>
<script type="text/javascript">
window.onload = function () {
var vm = new Vue({
el: '#box',
data: {},
methods: {
show: function (ev) {
if(ev.keyCode==13){
alert('你按了回车键!')
}
}
}
});
}
</script>
</head>
<body>
<div id="box">
<input type="text" @keyup="show($event)">
</div>
</body>
</html>
keyUp
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<script src="../js/Vue.js" charset="utf-8"></script>
<script type="text/javascript">
window.onload = function () {
var vm = new Vue({
el: '#box',
data: {},
methods: {
show: function (ev) {
alert(ev.keyCode)
}
}
});
}
</script>
</head>
<body>
<div id="box">
<input type="text" @keyup="show($event)">
</div>
</body>
</html>
键盘事件——简写方式
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<script src="../js/Vue.js" charset="utf-8"></script>
<script type="text/javascript">
window.onload = function () {
var vm = new Vue({
el: '#box',
data: {},
methods: {
show: function () {
alert('你按了回车!');
},
show2: function () {
alert('你按了回车!');
},
show3: function () {
alert('你按了上键!');
},
show4: function () {
alert('你按了下键!');
},
show5: function () {
alert('你按了左键!');
},
show6: function () {
alert('你按了右键!');
}
}
});
}
</script>
</head>
<body>
<div id="box">
<input type="text" @keyup.13="show()">
<hr>
<input type="text" @keyup.enter="show2()">
<hr>
<input type="text" @keyup.up="show3()">
<hr>
<input type="text" @keyup.down="show4()">
<hr>
<input type="text" @keyup.left="show5()">
<hr>
<input type="text" @keyup.right="show6()">
<hr>
</div>
</body>
</html>
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。
相关文章
Element el-table的formatter和scope template不能同时存在问题解决办法
本文主要介绍了ElementUI el-table 的 formatter 和 scope template 不能同时存在问题解决办法,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧2022-08-08


最新评论