vue+elementUI输入框回车会回到首页解决
<el-dialog-x :title="title" :visible.sync="foldDialogVisible"><el-form-x ref="foldForm" :group-fields="foldFields" :buttons="foldFormB
·
<el-dialog-x :title="title" :visible.sync="foldDialogVisible">
<el-form-x ref="foldForm" :group-fields="foldFields" :buttons="foldFormButtons"
label-width="120px" ></el-form-x>
</el-dialog-x>
以上是前端html书写的代码
js中代码如下
foldFields: [{
columnCount: 1,
fields: [
{
field: 'rootor', label: '根节点', type: "switch", change: function (rootor) {
if (rootor == true) {
this.rootOr = true;
} else {
this.rootOr = false;
}
}
},
{
field: 'constNm', label: '文件夹名称',type: "input", rules: [
{required: true, message: '必填项', trigger: 'blur'},
{max: 90, message: '输入值过长', trigger: 'blur'},
{validator: yufp.validator.trim, message: '输入项首尾有空格', trigger: 'blur'},
{validator: yufp.validator.speChar, message: '输入信息包含特殊字符', trigger: 'blur'},
{validator: yufp.validator.setCode, message: '名称不能数字开头', trigger: 'blur'}
]
},
{field: 'constDesc', label: '描述', type: "textarea", hidden: true, limitChar: {}},
{field: 'pjtCde', label: '项目编号', type: "textarea", hidden: true},
{field: 'parConstId', label: '父节点', type: "textarea", defaultValue: "", hidden: true},
{field: 'constId', label: '主键', type: "textarea", hidden: true},
{field: 'nodeTyp', label: '节点类型', type: "input", hidden: true},
{field: 'path', label: '路径', type: "input", hidden: true}
]
}],
页面效果如上,每次鼠标点击输入框后,不管是否输入数据,回车,都会跑到首页。查询好久无果。终于找到一丝线索
在form标签中增加 @submit.native.prevent
修改后代码如下
<el-dialog-x :title="title" :visible.sync="foldDialogVisible">
<el-form-x ref="foldForm" :group-fields="foldFields" :buttons="foldFormButtons"
label-width="120px" @submit.native.prevent></el-form-x>
</el-dialog-x>
这样就不会出现这个情况了。
原因 好像是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 元素中只有一个输入框时,在该输入框中按下回车应提交该表单。如果希望阻止这一默认行为,可以在 标签上添加 @submit.native.prevent。
但是看表单我的有好几条输入数据,哪怕将其的hidden修改为false。也是不行,而且仅仅这一条input不行,其他的回车都没事。改事件只是解决,具体原因不明,望大神给与指导更多推荐
已为社区贡献2条内容
所有评论(0)