我正在尝试实现 vue-i18n Vue-i18n Github,但出现错误:
vue.js:597 [Vue 警告]:未定义属性或方法“$t”
我的 vuejs 2 应用程序运行良好,直到我添加了加注星标的代码,我哪里错了?提前致谢
<div id="app">
<p>{{ $t("message.hello")}}</p>
</div>
<script src="https://unpkg.com/vue"></script>
<script src="https://unpkg.com/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>