I'm creating a Vue web component using vue-cli 4.5.13 and the --target wc option. I also need the component to use the vue-i18n-next plugin (last version for vue 3 projects), which requires some options to be passed to the main Vue instance, but now there is no main instance since the entrypoint is the vue component itself, so i18n has to be instantiated within the component.
I found this question for vue2:
How can I use vue-i18n in a Vue web component?
and it works for vue2, but instantiating the i18n
object in the component options is not valid for vue3 (this.$i18n stays undefined). So this is not working:
export default {
name: "custom-compo",
i18n: i18n,
components: { ChildComponent }
data, methods...
};
The solution should work both if exporting the web component (and using it on a standard page) and also if npm run serve
ing a standard app with this component inside (but again instantiating i18n in the compo as in answer to that question, not in main.js)
I am not asking how to setup vue-i18n within a normal vue project, but how to inisitalise i18n within a component that's gonna be built or exported as a custom-element or web-component, using the vue-cli, with vue 3.
I am not using composition api and setup(), but old options api. Just upgraded to vue3 package and changed deprecated syntax as per docs.