v-for循环中使用form表单验证TypeError: this.$refs[formName].validate is not a function

927 阅读1分钟

现象: 使用V-for循环生成form-item,在进行表单校验的时候使用文档常规的方法this.$refs[formName].validate 但是提示this.$refs[formName].validate is not a function

问题: 问题是this.$refs[formName]是一个数组,并且循环中所使用的表单验证是相同的,所以直接获取数组中的第一个

this.$refs[formName][0].validate((valid) => {}