Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic generated new Component instance can't find <i18n /> #1091

Closed
rockmandash opened this issue Dec 23, 2020 · 1 comment
Closed

Dynamic generated new Component instance can't find <i18n /> #1091

rockmandash opened this issue Dec 23, 2020 · 1 comment

Comments

@rockmandash
Copy link

rockmandash commented Dec 23, 2020

vue & vue-i18n version

2.6.11, 8.22.2

Reproduction Link

https://codesandbox.io/s/hopeful-vaughan-9wyn3?file=/src/main.js

Steps to reproduce

import Vue from "vue";

import VueI18n from "vue-i18n";

Vue.config.productionTip = false;

Vue.use(VueI18n);

const i18n = new VueI18n({
  locale: "en",

  messages: {
    en: {
      message: {
        helloFromParent: "Hello From Parent",
        helloFromChild: "Hello From Child"
      }
    }
  }
});

const Child = Vue.extend({
  render(h) {
    return h("div", null, this.$t("message.helloFromChild"));
  }
});

setTimeout(() => {
  const instance = new Child();
  instance.$mount();
  document.body.appendChild(instance.$el);
}, 3000);

new Vue({
  i18n,
  render(h) {
    return h("div", null, this.$t("message.helloFromParent"));
  }
}).$mount("#app");

What is Expected?

Working normally.

What is actually happening?

console warns

[Vue warn]: Error in render: "TypeError: Cannot read property '_t' of undefined"

TypeError: Cannot read property '_t' of undefined

@kazupon
Copy link
Owner

kazupon commented Apr 17, 2021

VueI18n instance isn't set to Child.
you need to set it to Child

thanks!

@kazupon kazupon closed this as completed Apr 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants