可以通过自定义属性required设置组件必填验证, 可以实现验证不同value类型的表单组件必填
required
value
type required = boolean | string | { message ?: String; trigger ?: String; required ?: boolean; validator ?: Function; }
<template> <div> <form-create :rule="rule" v-model="fApi" :option="options"/> </div> </template> <script> export default { data(){ return { fApi:{}, options:{ onSubmit:(formData)=>{ alert(JSON.stringify(formData)) } }, rule:[ { type:'input', field:'input', title:'input', value:'', effect:{ required: true } } ] } } } </script>
<template> <div> <form-create :rule="rule" v-model="fApi" :option="options"/> </div> </template> <script> export default { data(){ return { fApi:{}, options:{ onSubmit:(formData)=>{ alert(JSON.stringify(formData)) } }, rule:[ { type:'input', field:'input', title:'input', value:'', effect:{ required: '请输入内容' } } ] } } } </script>
← 加载异步数据 自定义布局 →