指令修饰符:
通过"."指明一些指令后缀,不同后缀封装了不同的处理操作 ->简化代码
①按键修饰符
@keyup.enter ->键盘回车监听
".enter"==if(e.key==='enter'){} //".enter"用来简化代码
demo:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div id="app">
<h3>@key-up.enter ->监听键盘回车事件</h3>
<input @keyup.enter="fn" v-model="username" type="text">
</div>
<script src="js/vue.js"></script>
<script>
const app = new Vue({
el: '#app',
data: {
username: ''
},
methods: {
fn() {
console.log('键盘回车的时候触发',this.username)
}
}
})
</script>
</body>
</html>