vue添加回车事件

1.普通input版

//js
<input v-on:keyup.13="submit">
//vue
<input @keyup.enter="submit">

2.如果按钮不是input的时候

如果按钮不是input,可以直接绑定在document上即可

   created() {
        var _this = this;
        document.onkeydown = function (e) {
            let key = window.event.keyCode;
            if (key == 13) {
                _this.login();
            }
        };

    },

参考链接1

参考链接2

发布了70 篇原创文章 · 获赞 56 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/weixin_44251396/article/details/103852295
今日推荐