element 使用v-if切换表单项时校验错误会错乱

bakd9h0s  于 4个月前  发布在  其他
关注(0)|答案(2)|浏览(85)

以下是我做的demo,可以把html和js赋值到codepan去跑,校验的错误在切换时会带到另外的form-item上

立即创建 重置
var Main = { data() { return { ruleForm: { name: '', region: '', date1: '', date2: '', delivery: false, type: [], resource: '', desc: '' }, rules: { name: [ { required: true, message: '请输入名称', trigger: 'blur' } ], age: [ { required: true, message: '请输入年龄', trigger: 'blur' } ], sex: [ { required: true, message: '请输入性别', trigger: 'blur' } ], address: [ { required: true, message: '请输入地址', trigger: 'blur' } ], } }; }, methods: { submitForm(formName) { this.$refs[formName].validate((valid) => { if (valid) { alert('submit!'); } else { console.log('error submit!!'); return false; } }); }, resetForm(formName) { this.$refs[formName].resetFields(); } } } var Ctor = Vue.extend(Main) new Ctor().$mount('#app')

brgchamk

brgchamk1#

需要给el-form-item加一个属性 key

zujrkrfu

zujrkrfu2#

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

相关问题