我正在尝试更改vee-validate为使用momement.js库的函数生成的错误消息。我可以更改其他验证规则的消息,例如'required',但不能更改'date_format‘、'before’或'after‘的消息。这是因为这些规则使用了moment.js库吗?有什么方法可以改变这些错误消息吗?
Vue.use(VeeValidate,{
fieldsBagName: 'vFields',
dictionary: {
en: {
messages: {
required: 'Your field is empty', // messages can be strings as well.
date_format: 'wrong format for date',
after:"date is too old",
}
}
}
});
new Vue({
methods: {
validate() {
this.$validator.validateAll().then(() => {
alert('Is valid')
}).catch(() => {
alert('Is not valid')
})
}
}
}).$mount('#app')See JSFiddle
发布于 2017-11-09 10:57:06
我已经在我的组件中使用以下代码实现了这一点:
import VeeValidate from 'vee-validate'
const dictionary = {
en: {
messages: {
after: (field, args) => `The ${field} must be greater than ${moment(args, moment.defaultFormat).format('YYYY-MM-DD HH:mm')}.`,
date_format: (field, args) => `The ${field} is invalid.`
}
}
}
VeeValidate.Validator.updateDictionary(dictionary);https://stackoverflow.com/questions/45172527
复制相似问题