Highchart Vue-如何包含momentjs?

时间:2018-07-23 20:51:46

标签: javascript vue.js highcharts momentjs

我正在尝试将vue-highchartsmoment.js一起使用。

<template>
    <highcharts :constructor-type="'stockChart'" :options="stockOptions" :updateArgs="[true, false]"></highcharts>
</template>

<script>
...
    stockOptions: {
       series: [{
          data: ''
       }],
       plotOptions: {
          series: {
                turboThreshold: 0
          }
       },
       chart: {
            type: 'area'
       },
       time: {
            timezone: 'America/Sao_paulo'
       }
    }
...
</script>

但是我收到此错误:

Highcharts Error #25
Can't find Moment.js library
Using the global.timezone option requires the Moment.js library to be loaded.

该如何解决?

1 个答案:

答案 0 :(得分:5)

Highcharts将检查type Test = {a: number}范围内的moment.js库是否可用,这就是为什么需要在此处添加它。首先,您需要导入两个模块:

window

然后运行将其分配为import Moment from "moment"; import MomentTimeZone from "moment-timezone"; 变量,并调用window模块函数:

moment-timezone

实时示例:https://codesandbox.io/s/n0v72938j