首页 > 解决方案 > 从 vuejs 组件访问 i18n 值

问题描述

我使用 i18n 为应用程序提供多语言支持,我希望我为 highcharts 提供的图表具有相同的行为。

<i18n>
{
  "fr": {
    "test": "en fançais"
  },
  "en": {
    "test": "in english"
  } 
}
</i18n>

<template>
    <highcharts :options="options"></highcharts>
</template>

<script>
import '@/plugins/highcharts.js'

export default {
  data() {
    return {
      options: {
        chart: {
          type: 'bar'
        },
        series: [{
          name: $t('test'),
          data: [1.0, 0.3, 0],
          color: '#beab9d'
        }],
        xAxis: {
          categories: ["1", "2", "3"]
        }
      }
    }
  }
}
</script>

但是在构建应用程序时,我得到了:

'$t' is not defined

有一种方法可以从组件的脚本部分访问 i18n 值吗?

标签: vue.jshighchartsinternationalization

解决方案


推荐阅读