【发布时间】:2020-07-30 08:01:44
【问题描述】:
我有以下初始化 Google Charts 的 ES 模块。
mychart.js
let redraw;
function init(data) {
// Do stuff to populate the chart
// [...]
// Set the redraw function which will be called on resize
redraw = () => chart.draw(data, chartOptions);
redraw();
$(window).resize(redraw);
}
export default { redraw, init, [...] };
main.js
import Mychart from './mychart';
$('#specific-button').on('click', function() {
$('#chart-container').toggle(function() {
// Also call redraw function when toggling HTML container visible
if ($('#chart-container').is(':visible')) {
Mychart.redraw();
}
});
});
$.ajax(/* Some ajax query */,
success: function(data) {
// First init of the Chart
Mychart.init(data);
}
);
当我的网页显示时,图表可以正常工作,并且在 window.resize 事件上正确调整大小。但是当我单击#specific-button 元素时,它会抛出undefined 错误。有什么办法解决这个问题?
main.js?dbbb:47 Uncaught TypeError: _main_mychart__WEBPACK_IMPORTED_MODULE_1__.default.redraw is not a function
【问题讨论】:
标签: javascript ecmascript-6 es6-modules