Vue
HTML
<div id="app">
<h2>Example:</h2>
<div tabindex="0" id="foo" v-on:keydown.esc="upCounter">
Just a div
</div>
<label>
<input type="text" v-on:keydown.esc="upCounter" />
</label>
<div>
<span>Event count: {{ counter }}</span>
</div>
</div>
CSS
body {
background: #20262E;
padding: 20px;
font-family: Helvetica;
}
#app {
background: #fff;
border-radius: 4px;
padding: 20px;
transition: all 0.2s;
}
#foo {
background-color: #ffddff;
}
Vue
new Vue({
el: "#app",
data: {
counter: 0
},
mounted: function() {
document.getElementById('foo').focus();
},
methods: {
upCounter: function(){
this.counter++
}
}
})