VUE JS - Vee Validate - 从错误消息中删除前缀

VUE JS - Vee Validate - Remove prefix from error message

我正在尝试从 vee-validate 错误消息中删除前缀。 每个错误字段都返回前缀 The 例如:The field_name is required.

我知道我可以用这样的自定义错误消息来改变它。

const dict = {
    custom: {
      field_name: {
        required: 'field_name is required.'
      }
    }
};
this.$validator.localize('en', dict);

但是这样太过分了,因为我有很多领域,这不是一个 DRY 概念。

有更好的方法吗?

我找到了一种无需自定义消息的更好方法,但可能不适用于所有人。 使用 OOP 我正在遍历 error bag 并删除字符串 The.

这是我的做法。

this.$validator.validateAll().then(result => {
  if (!result) {
    for (var i = 0; i < this.errors.items.length; i++) {
      this.errors.items[i].msg = this.errors.items[i].msg.replace(/^The /, '');
    }
    return false;
  }
});