<uni-forms ref="formDataRef" :model="formData" :rules="rules" label-width="80px">
<uni-forms-item label="企业名称" :name="['enterpriseInfo', 'enterpriseName']" required>
<uni-easyinput v-model="formData.enterpriseInfo.enterpriseName" placeholder="请输入企业名称" />
</uni-forms-item>
</uni-forms>
import {ref} from "vue";
const formDataRef = ref(null);
const formData = ref({
enterpriseInfo: {
enterpriseName: "", // 企业名称
}
})
const rules = ref({
enterpriseName: {
rules: [{
required: true,
errorMessage: "清填写企业名称",
}, ],
},
})
// 确定按钮的点击事件
function sumbit() {
formDataRef.value.validate((valid, data) => {
console.log("表单数据", formData);
console.log(valid, data);
});
// emit('changeActiveIndex',2)
}
1 个回复
DCloud_UNI_HT
需要给uni-forms-item 设置单独设置校验规则 rules ,看了下你的代码 ,你写的动态校验 ,无法匹配到有效的校验规则