javascript - vue.js:597 [Vue warn]: Property or method "$t" is not defined - Stack Overflow
I am trying to implement vue-i18n Vue-i18n Github and I 'have got an error :
vue.js:597 [Vue warn]: Property or method "$t" is not defined
My vuejs 2 app is working fine until I add the getting starded code, where am I wrong? Thanks in advance
<div id="app">
<p>{{ $t("message.hello")}}</p>
</div>
<script src=""></script>
<script src=".js"></script>
<script>
const app = new Vue({
el: '#app',
data: {
products: [
'Boots',
]
},
})
</script>
<script>
// Ready translated locale messages
const messages = {
en: {
message: {
hello: 'hello world'
}
},
ja: {
message: {
hello: 'こんにちは、世界'
}
}
}
// Create VueI18n instance with options
const i18n = new VueI18n({
locale: 'ja', // set locale
messages, // set locale messages
})
// Create a Vue instance with `i18n` option
new Vue({ i18n }).$mount('#app')
// Now the app has started!
</script>
I am trying to implement vue-i18n Vue-i18n Github and I 'have got an error :
vue.js:597 [Vue warn]: Property or method "$t" is not defined
My vuejs 2 app is working fine until I add the getting starded code, where am I wrong? Thanks in advance
<div id="app">
<p>{{ $t("message.hello")}}</p>
</div>
<script src="https://unpkg./vue"></script>
<script src="https://unpkg./vue-i18n/dist/vue-i18n.js"></script>
<script>
const app = new Vue({
el: '#app',
data: {
products: [
'Boots',
]
},
})
</script>
<script>
// Ready translated locale messages
const messages = {
en: {
message: {
hello: 'hello world'
}
},
ja: {
message: {
hello: 'こんにちは、世界'
}
}
}
// Create VueI18n instance with options
const i18n = new VueI18n({
locale: 'ja', // set locale
messages, // set locale messages
})
// Create a Vue instance with `i18n` option
new Vue({ i18n }).$mount('#app')
// Now the app has started!
</script>
Share
Improve this question
asked Apr 11, 2018 at 12:53
Emile CanteroEmile Cantero
2,0636 gold badges26 silver badges48 bronze badges
1
- Why do you have 2 instance of Vue, both mounting on #app? You can remove the first one and move your data to the one with the translations. – thefallen Commented Apr 11, 2018 at 13:08
1 Answer
Reset to default 1You have to specify i18n
in any Vue instance you want vue-i18n to work.
The first instance you have has no i18n
specified.
Besides, you have two Vue instances, they don't work together, so what you probably need is just one (with i18n
specified).
<div id="app">
<p>{{ $t("message.hello")}}</p>
</div>
<script src="https://unpkg./vue"></script>
<script src="https://unpkg./vue-i18n/dist/vue-i18n.js"></script>
<script>
// Ready translated locale messages
const messages = {
en: {
message: {
hello: 'hello world'
}
},
ja: {
message: {
hello: 'こんにちは、世界'
}
}
}
// Create VueI18n instance with options
const i18n = new VueI18n({
locale: 'ja', // set locale
messages, // set locale messages
})
// Create a Vue instance with `i18n` option
const app = new Vue({
el: '#app',
i18n, // this is equivalent to `i18n: i18n,` (without quotes, naturally)
data: {
products: [
'Boots',
]
},
})
// Now the app has started!
</script>
- 苹果兜售没用软件脸不红心不跳
- html - HTML5 Canvas: How to draw on Canvas from Java or C++ server? - Stack Overflow
- python - tensorflow-gpu installation failed in colab - Stack Overflow
- excel - When loading my userform i get Run-Time Error 381: Could not set the list property. Invalid property array index - Stack
- excel - Sum with multiple criteria and first matches only (excluding duplicates) - Stack Overflow
- How do you use partitions in Music Player Daemon (MPD) - Stack Overflow
- android - Slow screen value detection using root access and uiautomator in Kotlin – Optimization help needed - Stack Overflow
- Parsing Swift Predicates into Database Statements with PredicateExpressions - Stack Overflow
- java - JAR works in Command Prompt but not in PHP - Stack Overflow
- c# - IdentityServer4 and returning an error in response - Stack Overflow
- apple swift: is forKey:fileSize considered accessing non-public API? - Stack Overflow
- VS Code extension for collapsing sub-folders - Stack Overflow
- Odoo: BOM Update Not Removing Deleted Items from RFQ in Purchase Orders - Stack Overflow
- flash - Movie clip loading display problem in ActionScript 2 - Stack Overflow
- google cloud platform - Querying public google_ads_transparency_center BQ table doesn't show all the needed data - Stack
- html - CSS "vertical-align: middle" doesn't shrink the height of the parent element of img - Stack Ove
- java - jOOQ transaction does not work as expected - Stack Overflow