企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
## 一 FormValid 介绍 ### data | 字段 | 类型 | 说明 | | :---: | :---: | --- | | rule_form | Object | 表达数据 | | rules | Object | 校验规则 | ``` { // 表单 rule_form: { name: '', images: [] }, // 规则 rules: { name: [{ type: 'text', message: '请输入名称', required: true }, { min: 3, max: 5, message: 'name长度在 3 到 5 个字符' } ], images: [{ type: 'Array', message: '请上传图片', required: true }] } } ``` - rules - item | 字段 | 类型 | 说明 | | :---: | :---: | --- | | type | String | 校验类型,string、array、int ;默认是 string 字符串类型 | | message | String | 错误提示信息 | | required | Boolean | 校验规则 | | min | Object | 校验规则 | | max | Object | 校验规则 | ### methods - validate 校验方法,校验成功返回true,校验时间toast提示并返回false ## 二 使用 1. mixin 引用 `FormValid` 2. 将表单数据写入 `rule_form` 3. 在页面端定义 `rules` ``` import { FormValid } from '@/utils/Mixin'; export default { mixins: [FormValid], data() { return { // 表单 rule_form: { name: '', password: '', images: [] }, // 规则 rules: { name: [{ type: 'text', message: '请输入名称', required: true }, { min: 3, max: 5, message: 'name长度在 3 到 5 个字符' } ], password: [{ type: 'text', message: '请输入密码', required: true }, { min: 6, max: 12, message: '密码长度在 6 到 12 个字符' } ], images: [{ type: 'Array', message: '请上传图片', required: true }] } } }, methods: { submitEvent() { if (this.validate()) { this.$ShowToast('校验成功') } } } }; ```