`$t` undefined in `.vue` file
See original GitHub issuevue & vue-i18n version
ex: 2.1.4, 5.0.1
Steps to reproduce
Everything works fine if I define the component directly:
Vue.component('form-builder', {
mounted: function() {
console.log(this.$t); // this will output the function's source code
}
});
but if I change this to
Vue.component('form-builder', require('./test.vue'));
and the content of the test.vue
is
<template>
<div>
</div>
</template>
<style>
</style>
<script>
export default {
mounted: function() {
console.log(this.$t); // it says undefined
},
}
</script>
Issue Analytics
- State:
- Created 7 years ago
- Comments:15 (4 by maintainers)
Top Results From Across the Web
Vue i18n-$t undefined outside template - Stack Overflow
3 Answers 3 · I still get this : Cannot read property '$t' of undefined · @NarryStoran Where is your const columns defined?...
Read more >How to fix "this is undefined" in Vue - Michael Thiessen
The likely cause of this is that you're mixing up your usage of regular functions and arrow functions. My guess is that you're...
Read more >Fix this is Undefined in Vue - Medium
We may or may not get an error message saying 'this is undefined'. We might just see that the variables that we expected...
Read more >Why am I getting a bunch of errors TS2532: "Foo is possibly ...
Hi all, This is my second production project with Vue. I'm using Vue3.js. I'm having no errors on dev. However, when I try...
Read more >[Vue 3 & Vite 2] Uncaught (in promise) TypeError: Cannot read ...
@auth0/auth0-spa-js: v1.21.0 node: v16.13.0 vue-router: v4.0.14 vue: v3.2.31 ... the function won't return anything so it is undefined.
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
I solved the problem by using
this.$i18n.t()
to translate strings in mydata
function. Maybe this is useful for the others who are having similar issues.this.$t is not a function this same issue here.
i18n v6.0.0 -alpha.1