Vue-js Vue-i18n dictionnay似乎没有加载

时间:2017-11-14 16:47:28

标签: vue.js internationalization vuejs2

我尝试将我的应用程序交织在一起,我使用了vue-i18n ......

在我的app.js中我有这个:

import Vue from 'vue';
import VueI18n from 'vue-i18n';

import App from './App';

Vue.use(VueI18n);

const messages = {
  en: {
    message: {
      hello: 'hello world',
    },
    hello: 'hello world',
  },
};

const i18n = new VueI18n({
  local: 'en',
  messages,
});

/* eslint-disable no-new */
new Vue({
  el: '#app',
  i18n,
  router,
  template: '<App/>',
  components: { App },
  render: h => h(App),
});

并且在...组件的孩子的孩子我尝试做一个简单的:

`this.$t('hello');`

但总是:[vue-i18n] Cannot translate the value of keypath 'hello'. Use the value of keypath as default.

所以我想我错过了一些东西,但我找不到原因!

1 个答案:

答案 0 :(得分:1)

local中有拼写错误,应为locale(您忘记了e

所以,这样做:

const i18n = new VueI18n({
  locale: 'en',
  messages,
});
相关问题