<template>
<el-form @submit.native.prevent>
<el-input v-model="inputVal" @keyup.enter.native="submitHandle"></el-input>
</el-form>
</template>
<script>
export default {
data() {
return {
inputVal:''
};
},
created() { },
mounted() { },
methods: {
submitHandle() {
console.log(1, this.inputVal);
}
},
}
</script>
W3C 标准中有如下规定:
When there is only one single-line text input field in a form, the user agent should accept Enter in that field as a request to submit the form.
即:当一个 form 元素中只有一个输入框时,在该输入框中按下回车应提交该表单。如果希望阻止这一默认行为,可以在
<el-form>
标签上添加@submit.native.prevent
。