VeeValidate 本地化 "类型'验证器'上不存在属性'区域设置'。"



我正在使用veevalidate,并且可以很好地适用于英语(默认值)但是,如果我尝试使用任何其他语言,我会遇到错误"属性'locale'在类型'验证器'上不存在。

这是我的代码:

import VeeValidate from 'vee-validate';
import french from 'vee-validate/dist/locale/fr';
Vue.use(VeeValidate);
@Component
export default class TestTest extends Vue {
locale: any; // I have tried locale: string='fr';
nextLocale() {
  return this.locale === 'en' ? 'French' : 'English';
}
changeLocale() {
  this.locale = this.$validator.locale === 'fr' ? 'en' : 'fr';
  this.$validator.setLocale(this.locale);
}    
 created() {
  this.$validator.updateDictionary({
  fr: {
    messages: french.messages,
  }
})
}
 // other none related code...
}

根据:
http://vee-validate.logaretm.com/localization.html#api

要动态更改组件中的语言环境,您必须像So

一样调用本地化
this.$validator.localize('fr', french)

,它应该正常工作(您不需要在上面的调用已经这样做时调用更新)

最新更新