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("我是回车");
        },

猜你喜欢

转载自www.cnblogs.com/u-damowang1/p/12158394.html