Javascript 如何在带有vee validate/yup的vuejs3应用程序中显示自定义错误消息?
在vuejs3应用程序中,是否有方法使用vee validate和yup显示自定义错误消息? 我使用占位符选择输入:Javascript 如何在带有vee validate/yup的vuejs3应用程序中显示自定义错误消息?,javascript,yup,vuejs3,Javascript,Yup,Vuejs3,在vuejs3应用程序中,是否有方法使用vee validate和yup显示自定义错误消息? 我使用占位符选择输入: <Field name="published" as="select" class="form-control editable_field" v-model=
<Field
name="published"
as="select"
class="form-control editable_field"
v-model="formSelectionPublished">
<option value="" disabled selected>- Select Category -</option>
<option v-for="(categoryPublishedLabel) in categoryPublishedLabels" :key="categoryPublishedLabel.code">
{{categoryPublishedLabel.label}}
</option>
</Field>
<ErrorMessage name="published" class="validation_error"/>
...
const categoryEditValidationRules = Yup.object().shape({
published: Yup.string().max(100).required().notOneOf(['- Select Category -']).label('Category published')
-选择类别-
{{categoryPublishedLabel.label}
...
const categoryEditValidationRules=Yup.object().shape({
已发布:Yup.string().max(100).required().notOneOf(['-Select Category-'])。label('Category published')
它工作正常,但我唯一需要替换的是错误消息:
发布的类别不能是以下值之一:-选择
类别-
我想显示字段所需的错误消息
在package.json中:
“vee验证”:“^4.0.0-beta.18”,
“vue”:“^3.0.0”,
“是”:“^0.29.3”
谢谢!看起来yup验证程序接受第二个参数作为自定义错误消息。所以决定是:
published: Yup.string().max(100).required().notOneOf(['- Select Category -'], 'Category published is a required field')
这对我有用