原来的校验信息
async-validator/lib/messages.js
文中的提示信息 如下
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.newMessages = newMessages;
function newMessages() {
return {
'default': 'Validation error on field %s',
required: '%s is required',
'enum': '%s must be one of %s',
whitespace: '%s cannot be empty',
date: {
format: '%s date %s is invalid for format %s',
parse: '%s date could not be parsed, %s is invalid ',
invalid: '%s date %s is invalid'
},
types: {
string: '%s is not a %s',
method: '%s is not a %s (function)',
array: '%s is not an %s',
object: '%s is not an %s',
number: '%s is not a %s',
date: '%s is not a %s',
boolean: '%s is not a %s',
integer: '%s is not an %s',
float: '%s is not a %s',
regexp: '%s is not a valid %s',
email: '%s is not a valid %s',
url: '%s is not a valid %s',
hex: '%s is not a valid %s'
},
string: {
len: '%s must be exactly %s characters',
min: '%s must be at least %s characters',
max: '%s cannot be longer than %s characters',
range: '%s must be between %s and %s characters'
},
number: {
len: '%s must equal %s',
min: '%s cannot be less than %s',
max: '%s cannot be greater than %s',
range: '%s must be between %s and %s'
},
array: {
len: '%s must be exactly %s in length',
min: '%s cannot be less than %s in length',
max: '%s cannot be greater than %s in length',
range: '%s must be between %s and %s in length'
},
pattern: {
mismatch: '%s value %s does not match pattern %s'
},
clone: function clone() {
var cloned = JSON.parse(JSON.stringify(this));
cloned.clone = this.clone;
return cloned;
}
};
}
var messages = exports.messages = newMessages();
修改为中文
将需要修改的配置写在一个js文件中,引入main.js中
// validator.js
import Schema from 'async-validator'
Schema.messages.required = fieldFun('该字段为必填项')
Schema.messages.types.string = fieldFun('类型错误,应为字符串')
Schema.messages.types.array = fieldFun('类型错误,应为数组')
Schema.messages.types.object = fieldFun('类型错误,应为对象')
Schema.messages.types.number = fieldFun('类型错误,应为数字')
Schema.messages.types.date = fieldFun('类型错误,应为日期格式')
function fieldFun(message){
return ()=>{
return message
}
}
// main.js文件
import '../validator.js'