问题描述
有没有办法将单个spa prop传递给vue i18n实例,并将其分配给消息i18n prop。
I18n 构造函数:
const i18n = new VueI18n({
locale: process.env.VUE_APP_I18N_LOCALE,messages: {},});
Vue single-spa 实例:
const vueLifecycles = singleSpaVue({
Vue,appOptions: {
el: '#account',render() {
return (
<App
eventBus={this.$data.eventBus}
lang={this.$data.lang}
></App>
);
},i18n,},});
信息:我无权访问渲染函数之外的 lang
。
基本上,我的 i18n 消息对象中需要 lang 属性。我已经尝试将 lang 返回到构造函数中,但它不起作用。
我还尝试在收到 lang
后重新实例化 i18n/messages,但也不起作用。
还有其他想法吗?
解决方法
所以我想通了。只能使用以下命令更改已挂载的 vue 实例中的消息:
this.$i18n.setLocaleMessage = newLangObj