input框绑定回车事件

1,198 阅读1分钟

页面中有个搜索功能,除了点击搜索按钮外再加个回车键搜索

下面是代码:

          <ct-form @submit.native.prevent>
            <ct-input
              type="text"
              placeholder="请输入候选人姓名"
              @input="input"
              @keyup.enter.native="searchVotePeople"
            />
            <ct-button @click="searchVotePeople">搜索</ct-button>
          </ct-form>

其中@keyup.enter.native是触发回车事件,@submit.native.prevent是防止提交后整个页面刷新(如果回车事件触发后是跳转页面的话可以不加@submit.native.prevent)