当 form 中只有一个 input 时回车时,会自动提交表单

901 阅读1分钟

当 form 中只有一个 input 时回车时,会自动提交表单

开发背景:vue+iview

解决方法:

1、在 Input 上加 @keydown.native.enter.prevent

如果需要回车执行某个事件:加 @keydown.native.enter.prevent ="test"

2、在 Form 上加 @submit.native.prevent

如果需要回车执行某个事件:加 @submit.native.prevent ="test"