以下是我做的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')
2条答案
按热度按时间brgchamk1#
需要给el-form-item加一个属性 key
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.