如何使用ant design vue 3在表单字段中设置从服务器获取的错误消息



问题是,我需要设置从后端检索到的错误消息(laravel(,并在出现错误时在每个字段上设置它。结构可能看起来像这样:

{
'errors': {
'email' : ['The Email field is required'],
'password' : ['The Password field is required'] 
}
}

在vuetify中,我只是在道具error-messages中设置了一个表单输入组件(error-messages=data.errors.email然后它会自动拾取第一个(。问题是,如何在蚂蚁设计vue 3中做到这一点?找不到任何。我试过了,但我不想使用createForm,因为我已经从惯性中使用了form。我也试过这个,但我几乎不明白。现在我被困了,我希望有人能帮助我,谢谢:(.

我挣扎了一段时间,但最终找到了对我有效的解决方案

<Form.Item
name="email"
label="Email"
:rules="[
{ required: true, message: 'Please input your email' },
{ type: 'email', message: 'Incorrect email' }
]"
:validateStatus="errors.email ? 'error' : undefined"
:help="errors.email || undefined"
>
<Input v-model:value="form.email" />
</Form.Item>

最新更新