通过单击事件,我更改了vue-i18n语言,我想将vee验证字典更改为同一种语言。
main.js
import VeeValidate from 'vee-validate'
import validations from './validations.js'
import i18n from './lang'
Vue.use(VeeValidate)
new Vue({
router,
store,
i18n,
render: h => h(App)
}).$mount('#app')vue-i18n文件夹> lang/index.js
import Vue from 'vue'
import VueI18n from 'vue-i18n'
import en from './locals/en'
import es from './locals/es'
Vue.use(VueI18n)
export default new VueI18n({
locale: 'en',
messages: {
en: {
lang: en
},
es: {
lang: es
}
}
})vee-验证文件夹> src/validations.js
import {Validator} from 'vee-validate'
const dictionary = {
en: {
custom: {
signupEmail: {
required: 'Error',
},
}
},
es: {
custom: {
signupEmail: {
required: 'Hubo un error',
},
}
}
}
Validator.localize(dictionary)
const validator = new Validator()
validator.localize('en')
export default ValidatorI试图以validator.localize('en')为目标,我不能更改es字典,即使我手动更改它(‘es’)。我错过了什么?
发布于 2020-07-11 15:35:51
我自己想好了该怎么做。
在安装的循环钩子内的App.vue集中
VeeValidate.Validator.locale = `${language}`发布于 2020-06-29 13:07:14
看上去你很接近,但少了几个关键的部分。
当您连接到传递一个对象 VeeValidate时,您可以这样做:
Vue.use(VeeValidate, {
i18nRootKey: 'custom', // customize the root path for validation messages.
i18n,
dictionary: {
en: {
custom: {
signupEmail: {
required: 'Error',
},
}
},
es: {
custom: {
signupEmail: {
required: 'Hubo un error',
},
}
}
}
});显然,我只是将您的字典内联在这里,最好将它保存为单独的文件,然后以这种方式导入它。
https://stackoverflow.com/questions/62582753
复制相似问题