我正在寻求帮助与Vite有关的错误。试图使用Vite将ApexCharts导入新的Laravel应用程序。
ApexCharts安装文档上的以下步骤:https://apexcharts.com/docs/installation/
NPM安装成功。我已经将导入添加到我的app.js文件中:
import ApexCharts from 'apexcharts';
使用npm运行Vite servier。我没有任何错误。
我正在尝试加载一个已剥离的刀片文件以进行故障排除:
@vite(['resources/js/app.js']);
<div id="test"></div>
<script type="module">
var options = {
chart: {
type: 'line'
},
series: [{
name: 'sales',
data: [30,40,35,50,49,60,70,91,125]
}],
xaxis: {
categories: [1991,1992,1993,1994,1995,1996,1997, 1998,1999]
}
}
var chart = new ApexCharts(document.getElementById('test'), options);
chart.render();
</script>
我知道错误:
(index):19 Uncaught ReferenceError: ApexCharts is not defined
at (index):19:17
我试着运行npm,ApexCharts导入在构建资产中。
我在想,这可能是一个加载顺序问题,但是即使在页面加载完成后,我尝试创建一个新的ApexCharts,我也会得到一个不明确的引用错误。
如有任何帮助,将不胜感激!
发布于 2022-11-02 02:54:42
import ApexCharts from 'apexcharts';
window.ApexCharts = ApexCharts; // return apex chart
基于apexcharts.js
,为了导入它,您需要首先为它定义变量,并且需要通过window.ApexCharts
公开它,以便在webpack包之外使用它
https://stackoverflow.com/questions/74281687
复制相似问题