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

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

如果 vuejs3 应用程序中有 vee-validate 和 yup 显示自定义错误消息的方法? 我用占位符输入 select 输入:

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

它工作正常,但我唯一需要替换错误消息的是:

Category published must not be one of the following values: - Select Category -

我想显示字段必填错误消息...

在package.json中:

"vee-validate": "^4.0.0-beta.18", "vue": "^3.0.0", “是的”:“^0.29.3”

谢谢!

看起来是的验证器接受第二个参数作为自定义错误消息。所以决定是:

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

对我有用!