Vite + Vue3 (SFC) TypeError: this.$t is not a function
See original GitHub issuevue & vue-i18n version
- vue: 3.0.5
- vue-i18n: 9.0.0-rc.6
- vite: 2.0.0-beta.69
Hi, I am upgrading my Vue2 project to vue3 and followed the vue 3 and vue-i18n-next docs to setup the project using Vite. However, I get this.$t is not a function error in my SFC vue component. BTW, I am using the legacy options api.
It seems the global $t is not assigned for some reason. Looking for some hints to resolve this issue.
// main.ts
import { createApp } from "vue";
import App from "./App.vue";
...
import { createI18n } from "vue-i18n";
const app = createApp(App);
const i18n = createI18n({
locale: "en",
fallbackLocale: "en",
silentFallbackWarn: true,
messages: {
en: {
title: "Hello",
},
},
});
app.use(i18n);
app.mount("#app");
// App.vue
<template>
<div>{{ $t('title') }}</div>
...
</template>
<script lang="ts">
export default {
};
</script>
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
TypeError: _ctx.$t is not a function when using $t in child ...
Ok in fact I'm trying to use single file component based translations (as described here: https://vue-i18n.intlify.dev/guide/advanced/sfc.html) ...
Read more >vue 3 typescript Uncaught (in promise) TypeError: this.$on is ...
I think the problem is not related to Vue3. It is related to typescript. Just add this package @types/vue-select .
Read more >Uncaught TypeError: Object(...) is not a function in Vue3
I have strange error, i don't know what causing this but last time i develop my project was fine. After no reason my...
Read more >vue cannot set properties of undefined - You.com | The AI ...
Steps to reproduce · 1) Make an instance of an object with an implicitely 'undefined' property in prototype: const someObj = function() {};...
Read more >Generically Typed Vue Components with Composition API
js is a functional component, and with Vue 3 we can easily just use a single setup function as an argument to defineComponent...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thank you for your feedback.
Sorry, poor documentation. If you don’t configure
vue-plugin-vue-i18n
plugincompositionOnly
tofalse
, you need to configure it. https://github.com/intlify/vite-plugin-vue-i18n#compositiononlyWhen this plugin set to your app, it will work for Composition API as default.
Hi,
I’m not sure what I am missing… but how can I load the SFC messages instead?
I’ve pretty much tried everything… enable and disable legacy mode, set the
compositionOnly: false
… and theglobalInjection: true
If I don’t set
globalInjection: true
I get theTypeError: _ctx.$t is not a function....
But if i set it to true, then the messages I put inside the SFC doesn’t load.
How can I get this to work? Thanks