简体   繁体   English

如何在带有 vee-validate/yup 的 vuejs3 应用程序中显示自定义错误消息?

[英]How in vuejs3 app with vee-validate/yup to show custom error message?

If there is a way in vuejs3 app with vee-validate and yup to show custom error message?如果 vuejs3 应用程序中有一种方法可以使用 vee-validate 和 yup 来显示自定义错误消息? I make select input input with placeholder:我使用占位符进行选择输入输入:

              <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')

and it works ok, but the only thing I need to replace error message :它工作正常,但我唯一需要替换错误消息的是:

Category published must not be one of the following values: - Select Category -发布的类别不得是以下值之一: - 选择类别 -

I would like to show field required error message...我想显示需要字段的错误消息...

In package.json :在 package.json 中:

"vee-validate": "^4.0.0-beta.18", "vue": "^3.0.0", "yup": "^0.29.3" "vee-validate": "^4.0.0-beta.18", "vue": "^3.0.0", "yup": "^0.29.3"

Thanks!谢谢!

looks like yup validators accept a second argument as a custom error message.看起来是的验证器接受第二个参数作为自定义错误消息。 So decision is :所以决定是:

  published: Yup.string().max(100).required().notOneOf(['- Select Category -'], 'Category published is a required field')

It workd for me!它对我有用!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM