Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

vue.js - Pass single-spa prop to i18n instantiation

is there a way to pass a single-spa prop to a vue i18n instance, assigning it to the messages i18n prop.

I18n constructor:

const i18n = new VueI18n({
  locale: process.env.VUE_APP_I18N_LOCALE,
  messages: {},
});

Vue single-spa instance:

const vueLifecycles = singleSpaVue({
  Vue,
  appOptions: {
    el: '#account',
    render() {
      return (
        <App
          eventBus={this.$data.eventBus}
          lang={this.$data.lang}
        ></App>
      );
    },
    i18n,
  },
});

Info: I dont have access to lang outside the render function.

Basically, I need the lang prop inside my i18n messages object. I tried already to return the lang and but it into the constructor, doesnt work. I also tried to reinstantiate i18n/messages after lang is received, doesnt work either. Any other ideas?

question from:https://stackoverflow.com/questions/65836666/pass-single-spa-prop-to-i18n-instantiation

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

So I figured it out. It is only possible to alter the messages in your mounted vue instance with:

this.$i18n.setLocaleMessage = newLangObj

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...