Vue监听回车事件

  • 生命周期函数创建之后,响应回车事件
    created: function() {
    var _this = this;
    document.onkeydown = function(e) {   //按下回车提交
        let key = window.event.keyCode;  
        //事件中keycode=13为回车事件
        if (key == 13) {
            _this.append();
        }
    };
    },
  • 事件方法
    append: function() {
            alert("我是回车");
        },
posted @ 2020-01-06 20:38  手可摘星辰/*  阅读(4850)  评论(0)    收藏  举报