我正在使用最新的Backbone-boilerplate,它采用 ECMAScript 2015 作为默认语法。我计划在这个项目上使用HighChartsimport
,但遇到了 Highcharts 的问题。
我的实现如下。
Backbone.View
home.js(这是Backbone-boilerplate的默认索引)
import Component from '../../component';
import template from './home.html';
import Pitch from '../../modules/pitches/index';
import $ from 'jquery';
import highcharts from 'highcharts-release/highcharts';
// Import components.
import '../components/sample-component';
export default Component.extend({
template,
initialize: function () {
this.template.registerPartial('nav', require('../partials/nav.html'));
this.collection = new Pitch.Collection();
this.collection.fetch({});
this.listenTo(this.collection, 'reset sync', this.render);
},
afterRender: function () {
$('#container').highcharts({
chart: {
type: 'scatter',
zoomType: 'xy'
},
title: {
text: 'Title'
},
subtitle: {
text: 'Subtitle'
}
});
}
});
我尝试了不同的组合来让它工作,但没有一个成功。
import highcharts from 'highcharts-release/highcharts'
import highcharts from 'highcharts'
import 'highcharts-release/highcharts'
import 'highcharts'
我收到这个错误,似乎 Highcharts 根本没有被导入。
未捕获的 TypeError: (0 , _jquery2.default)(...).highcharts 不是函数
以 ECMAScript 2015 方式导入 HighCharts 的正确方法是什么?