由于我项目的原因,企业和个人个表单不一样,通过给isView的true和false来控制

首先企业默认的是true,所以可以在created里面判断
created() {
if (this.isView) {
// 个人表单校验失效
this.rules.personName[0].required = false
// 或者这样写也可以
this.$refs['formName'].clearValidate('xxx')
}
},
然后再在methods方法里面点击了企业个人表单按钮时再判断
handelPerson() {
this.isView = false
if (!this.isView) {
// 企业表单校验失效
this.rules.pwuName[0].required = false
this.rules.personName[0].required = true
// 或者这样写也可以
this.$refs['formName'].clearValidate('xxx')
}
},
本文介绍如何在Vue项目中,根据不同场景(如企业或个人表单)动态切换表单校验规则,通过控制isView变量实现校验逻辑的启用与禁用。
177

被折叠的 条评论
为什么被折叠?



