• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

vue + el-form 实现的多层循环表单验证

vue 搞代码 4年前 (2022-01-08) 69次浏览 已收录 0个评论

这篇文章主要介绍了vue + el-form 实现的多层循环表单验证,帮助大家更好的理解和使用vue框架,感兴趣的朋友可以了解下。

html

    <div class="hljl-container">    <!--@blur="isRepeat(formItem, index, 'fieldName')"-->   </div>

js

 let _THAT export default { name: 'formMangeAdd', data() { return { formObj: { formDictExtendDoList: [] }, rules: { fieldName: [{ required: true, message: '请输入', trigger: 'blur' }, { validator: this.itemValidator, trigger: 'blur' }], value: [{ validator: (rule, value, callback) = > { // I'm a genius. let that = _THAT that.forceUpdate() let field = rule.field let arr = field.split('.') let index = +arr[1] let index1 = +arr[3] let _value = that.formObj.formDictExtendDoList[index].item[index1].value if (_value === '' || _value === null || _value === undefined) { callback(new Error('请输入')) } else { callback() } }, trigger: 'blur' }] } } }, beforeCreate() { _THAT = this }, created() { // 测试数据 let test = [{ id: 'id_1595641858891', // 唯一配置id fieldName: '字段名称', // 字段名称 item: [] }, { id: 'id_1595641858892', // 唯一配置id fieldName: '字段名称', // 字段名称 item: [] }, { id: 'id_1595641858893', // 唯<span style="color:transparent">本文来源gaodai#ma#com搞*!代#%^码网%</span>一配置id fieldName: '字段名称', // 字段名称 item: [{ id: 'item_id_1595641858891', // 唯一id value: '选项1' }, { id: 'item_id_1595641858892', // 唯一id value: '选项2' }] }] this.formObj.formDictExtendDoList = test }, methods: { /** * 重复性判断 **/ itemValidator: (rule, value, callback) = > { let that = _THAT that.forceUpdate() let field = rule.field let ruleArr = field.split('.') let index = +ruleArr[1] let type = ruleArr[2] if (value === '') { callback() return false } let arr = [] for (let i = 0; i <that.formObj.formDictExtendDoList.length; i++) { let formDictExtendDoListItem = that.formObj.formDictExtendDoList[i] let formDictExtendDoListFieldName = formDictExtendDoListItem.fieldName let formDictExtendDoListProjectName = formDictExtendDoListItem.projectName if (index !== i) { if (type === 'fieldName') { if (formDictExtendDoListFieldName !== '') { if (formDictExtendDoListFieldName === value) { arr.push(i) } } } } } if (arr.length !== 0) { if (type === 'fieldName') { callback(new Error('与配置' + (+arr[0] + 1) + '的字段名称重复')) setTimeout(function() { that.formObj.formDictExtendDoList[index].fieldName = '' }, 500) } } else { callback() } }, forceUpdate() { this.$forceUpdate() } } }

以上就是vue + el-form 实现的多层循环表单验证的详细内容,更多请关注gaodaima搞代码网其它相关文章!


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:vue + el-form 实现的多层循环表单验证
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址