【问题标题】:Translate string in vuejs component in a .js file在 .js 文件中翻译 vuejs 组件中的字符串
【发布时间】:2018-07-25 17:28:01
【问题描述】:

我安装了这个包来在我的应用程序 laravel 和 vuejs 中进行翻译:laravel-vue-i18n-generator

我生成了如下所示的语言文件

export default {
"en": {
    "API": "API",
    …
"fr": {
    "API": "Mon API"
 }

在我的 .Vue 文件中,我可以这样做来翻译我的文本:

{ $t('message.API' }}

只有我的一些组件使用 .js 文件。

Vue.component('update-team-profile-details', {
  data() {
    return {
      …
  },

  mounted() {
    …
  },

  methods: {
    update() {
      Spark.put(this.urlForUpdate, this.form)
          .then(success => {
            // is success
            this.validateSuccess()
          }).catch(error => {
        // is error
        this.validateError();
      });
    },

    validateSuccess() {
      if (this.form.successful) {
        this.$message({
          message: $t('message.API),
          type: 'success'
        });
      }
    },

    validateError() {
      this.$message.error('Désolé… vos informations n’ont pas été sauvegardées. Veuillez corriger les erreurs et réessayer.');
    }
  }
  }
});

我正在尝试将消息字符串替换为$t('message.API),但它不起作用,你有什么想法吗?

谢谢

【问题讨论】:

  • 好像this.$t('message.API')
  • 您没有关闭字符串,也没有引用 Vue 实例。它可能需要this.$t('message.API')

标签: javascript laravel vue.js vuejs2


【解决方案1】:

正如 Sphinx 和Thanksd 所说,我只是忘记了这个...... tsss

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-09-30
    • 1970-01-01
    • 2019-02-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-16
    相关资源
    最近更新 更多