ElementUI 的技巧记录

ElementUI 的技巧记录。背景:Vue2 + ElementUI **button 中添加 native-type="submit"**

表单

表单回车自动提交

背景:Vue2 + ElementUI

button 中添加 native-type=“submit”

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

1
2
3
4
5
6
7
8
9
<el-form :inline="true" :model="pageparm" @submit.native.prevent>
    <el-form-item>
        <el-input suffix-icon="el-icon-search" v-model="pageparm.searchContent" placeholder="搜索内容" style="width: 250px">
        </el-input>
    </el-form-item>
    <el-form-item>
        <el-button type="success" icon="el-icon-search" native-type="submit" @click="searchData()">搜索</el-button>
    </el-form-item>
</el-form>
Gear(夕照)的博客。记录开发、生活,以及一些不足为道的思考……