window.onkeydown = function(){
console.log(123)
}
在vue中如何写,绑定在哪里?
created:function(){
var _this = this;
window.onkeydown = function(e){
_this.aasd = e.keyCode;
}
}
这样写了
window.onkeydown = function(){
console.log(123)
}
在vue中如何写,绑定在哪里?
created:function(){
var _this = this;
window.onkeydown = function(e){
_this.aasd = e.keyCode;
}
}
这样写了
<template>
<input type="text" class="add-event" placeholder="请输入要做的事情" v-model="msg" @keyup.enter="log">
</template>
<script>
export default {
data() {
return {
msg: '',
test: ['hello', 'hello2'],
}
},
methods: {
log: function () {
this.test.push(this.msg);
}
}
}
</script>
10 回答11.2k 阅读
5 回答4.8k 阅读✓ 已解决
4 回答3.1k 阅读✓ 已解决
2 回答2.7k 阅读✓ 已解决
2 回答4.8k 阅读✓ 已解决
4 回答4.3k 阅读✓ 已解决
4 回答1.9k 阅读✓ 已解决
可以考虑在根组件的 created 钩子里写