question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`$t` undefined in `.vue` file

See original GitHub issue

vue & 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:closed
  • Created 7 years ago
  • Comments:15 (4 by maintainers)

github_iconTop GitHub Comments

44reactions
mawalucommented, Apr 9, 2017

I solved the problem by using this.$i18n.t() to translate strings in my data function. Maybe this is useful for the others who are having similar issues.

13reactions
bestkjcommented, Feb 25, 2017

this.$t is not a function this same issue here.

i18n v6.0.0 -alpha.1

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found