TypeError: _ctx.$t is not a function when using $t in child component
See original GitHub issuevue & vue-i18n version
- vue: 3.0.0
- vue-i18n: 9.0.0-rc.7
Reproduction Link
https://github.com/boussadjra/vue3-tailwind2
Steps to reproduce
I added a file named i18n.ts
next to main.ts
which contains the following snippet :
import { createI18n } from "vue-i18n";
const i18n = createI18n({
legacy: false,
locale: "ja",
messages: {
en: {
message: {
language: "English",
greeting: "Hello !"
}
},
ar: {
message: {
language: "العربية",
greeting: "السلام عليكم"
}
},
es: {
message: {
language: "Español",
greeting: "Hola !"
}
}
}
});
export default i18n;
then I imported the file inside main.ts
and use it :
...
import i18n from './i18n'
let root = app.use(i18n).use(store).use(router).mount('#app')
then I added the following snippet to home.vue
:
<h2>{{ $t("message.greeting", {}, { locale: "en" }) }}</h2>
What is Expected?
Render the message Hello !
What is actually happening?
but this is giving the following error :
Uncaught (in promise) TypeError: _ctx.$t is not a function at Proxy.render (Home.vue?bb51:2)
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:24
Top Results From Across the Web
TypeError: ctx.onCreditChange is not a function angular
CHILD COMPONENT. The error start here, because Output is not a function, it's an object that allow to you to send events to...
Read more >vue-i18n插件报错:Uncaught TypeError: _ctx.$t is not a function
在vite脚手架项目当中,使用vue-i18n插件进行国际化多语言时,爆出. Uncaught TypeError: _ctx.$t is not a function.
Read more >How to solve the "is not a function" error in JavaScript
js we use require() to load external modules and files. This can cause, in some cases, an error like this: TypeError: require(...) is...
Read more >Uncaught TypeError | Is Not A Function | Solution - YouTube
Transcript · DIV to PDF, Iframe to PDF using JavaScript Only ( with CSS & Images Support) · Top 5 Excel Functions for...
Read more >Making the most out of Vue.js Injections - Abdelrahman Awad
In other words, it "provides" some dependency to child components. ... allows you to pass complex reactive objects along with functions and ...
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
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
Hi, I think this may be similar to my issue, I found out that to have the global $t injected like on previous version I neet to pass
globalInjection: true,
in the createI18n() function options.So your
i18n.ts
may look like this:Vue3 and vue-i18n-next sample, it could works as bellow:
useI18n
:setup()
:t
in the template: