首页 > 解决方案 > 防止按钮上的输入键按下 - Vue

问题描述

我只想在点击事件上触发我的按钮(而不是按下回车键),它现在以动态方式工作:

<button class="btn btn-primary" type="button" v-on="{ click: isInProgress ? stop : start }">

我的问题是,如何将阻止修饰符以这种方式单击?我知道删除type="button"也可以解决问题,但我不能。

那么@click.prevent=""解决方案是v-on什么?提前致谢!

标签: javascripthtmlvue.js

解决方案


如果您想阻止“keydown.enter”触发按钮,您可以使用keydown.enter.prevent

 <button
    class=""
    type="button"
    v-on:keydown.enter.prevent
    v-on="{ click: isInProgress ? stop : start }"
  ></button>

推荐阅读