TypeError: Cannot read property '$i18n' of undefined
See original GitHub issuevue & vue-i18n version
ex: ^2.5.3,^7.3.2
Reproduction Link
Steps to reproduce
- Error: TypeError: Cannot read property ‘$i18n’ of undefined
export default {
data () {
const $t = this.$t;
return {
msg: $t('msg')
};
}
};
- Normal
export default {
data () {
const $t = this.$t.bind(this);
return {
msg: $t('msg')
};
}
};
What is Expected?
export default {
data () {
const $t = this.$t;
return {
msg: $t('msg')
};
}
};
What is actually happening?
This Not equal to component instance
/* @flow */
export default function extend (Vue: any): void {
Vue.prototype.$t = function (key: Path, ...values: any): TranslateResult {
const i18n = this.$i18n
return i18n._t(key, i18n.locale, i18n._getMessages(), this, ...values)
}
Vue.prototype.$tc = function (key: Path, choice?: number, ...values: any): TranslateResult {
const i18n = this.$i18n
return i18n._tc(key, i18n.locale, i18n._getMessages(), this, choice, ...values)
}
Vue.prototype.$te = function (key: Path, locale?: Locale): boolean {
const i18n = this.$i18n
return i18n._te(key, i18n.locale, i18n._getMessages(), locale)
}
Vue.prototype.$d = function (value: number | Date, ...args: any): DateTimeFormatResult {
return this.$i18n.d(value, ...args)
}
Vue.prototype.$n = function (value: number, ...args: any): NumberFormatResult {
return this.$i18n.n(value, ...args)
}
}
Issue Analytics
- State:
- Created 6 years ago
- Reactions:5
- Comments:13 (1 by maintainers)
Top Results From Across the Web
Vue-i18n - npm run serve fails with error TypeError: Cannot ...
I can give the following stack trace: TypeError: Cannot read property 'i18n' of undefined at module.exports (..\node_modules\vue-cli-plugin-i18n ...
Read more >How to fix Vue I18n Uncaught TypeError - Our Code World
How to fix Vue I18n Uncaught TypeError: Cannot read property 'config' of undefined. I've been working on a Vue.js app that needs to...
Read more >Uncaught (in promise) TypeError: Cannot read property 'i18n ...
Uncaught (in promise) TypeError: Cannot read property 'i18n' of undefined and the UI is broken. Storeview setting is as below:.
Read more >Using Vue18n can't get it to work - Laracasts
... Error in render: “TypeError: Cannot read property '_t' of undefined”. I don't know how to get this to work. I installed it...
Read more >Cannot read property '$i18n' of undefined when using Vue ...
[Solved]-Cannot read property '$i18n' of undefined when using Vue Test Utils-Vue.js ... The problem was I was referencing this in the props. Props...
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
Problems still exist. “vue-i18n”: “^8.0.0”
it’s very annoying, especially in render functions. I have to write
instead of