$t is undefined in data attributes
See original GitHub issuevue & vue-i18n version
vue@2.2.0 vue-i18n@6.0.0-alpha.2
Reproduction Link
http://codepen.io/hanspagel/pen/ryLwyo
Steps to reproduce
Use this.$t
in data
What is Expected?
Should return a translated string
What is actually happening?
this.$t is undefined
Issue Analytics
- State:
- Created 7 years ago
- Reactions:3
- Comments:11 (1 by maintainers)
Top Results From Across the Web
Data attribute is returning undefined - javascript - Stack Overflow
I am then trying to pick it up again on another onClick but it comes back as undefined. When I console log $(this).text();...
Read more >Data attribute value is undefined. - MSDN - Microsoft
I am trying to pass the controller and corresponding action method on a button click like below but I always get undefined on...
Read more >Built-in and Custom Data Attributes - Beginner JavaScript
When you are working with HTML elements, those elements have something called attributes. Attributes are anything provided to an element as additional ...
Read more >Data Attributes In JavaScript - Web Dev Simplified Blog
Let's say that we now want to update the value of a data attribute. This is incredibly easy since it works just like...
Read more >Function data attribute in child Datatable: "data is undefined"
According to the data option docs it expects the option to be an array. It is not expecting a function. This option can...
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
@acrolink The reason you’re getting that error is because you’re using an arrow function to return the
data
object sothis
isn’t bound correctly when you reference it. This happened to me too! To fix:Thank you for your reporting!
In
data
option, You need to usethis.$i18n.t
(VueI18n instance method). In the Vue lifecycle, data initialization withdata
option invoke beforecomputed
props initialization. In vue-i18n v6 later,$t
,$tc
and$te
are implemented withcomputed
prop of Vue.I’ll try to write about it as caveats into v6 documentation. 😃