VeeValidate本地化“属性'语言环境'在'验证者'类型上不存在。”

时间:2017-08-31 16:38:13

标签: localization vue.js

我正在使用VeeValidate并且非常适合英语(默认情况下) 但是,如果我尝试使用任何其他语言,我会收到错误说 “'验证者'类型中不存在”属性'语言环境'。“

这是我的代码:

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...

}

1 个答案:

答案 0 :(得分:2)

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

要动态更改组件中的区域设置,您必须像这样调用localize

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="outer">
	<div class="section1">
		<a href="#" class="btn" onclick="changecolor()"> Button </a>
		<p class="text" > Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. </p>
	</div>
	<div class="section1">
		<a href="#" class="btn" onclick="changecolor()"> Button </a>
		<p class="text" > Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. </p>		
	</div>
	<div class="section1">
		<a href="#" class="btn" onclick="changecolor()"> Button </a>
		<p class="text" > Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. </p>	</div>
</div>

它应该可以正常工作(你不需要调用updateDictionary,因为上面的调用已经在这样做了)