电子“窗口”未定义

Mag*_*les 6 electron

我正在尝试构建一个使用Google Charts API绘制折线图的应用程序。我设置的一件事是窗口上的'resize'事件的事件监听器。这将触发折线图重新绘制,尺寸设置为“ window.innerWidth”和“ window.innerHeight”以适应新的窗口大小。

如果我使用npm start运行应用程序,那么一切都很好。问题是当我使用电子打包程序构建应用程序时。运行它生成的exe会抛出此错误:在此处输入图片说明

这是我的HTML:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8">
    <title>AP Test Viewer</title>
    <link rel="stylesheet" href="css/styles.css">

  </head>
  <body ng-app="ApApp" ng-controller="MainController">

    <a ui-sref="single">Single</a>
    <a ui-sref="multi">Multi</a>

    <ui-view></ui-view>


  </body>

  <script>
    // You can also require other files to run in this process
    require('./renderer.js');
    require('./js/loader.js'); //google charts loader.js
    require('./js/app.js');
  </script>
</html>
Run Code Online (Sandbox Code Playgroud)

以及我的应用程序的相关部分,在这里我使用window:

app.fun.drawGraph = function(){
    if(app.data.graphConfig){
        app.data.graphConfig.options.width = window.innerWidth * 0.97;
        app.data.graphConfig.options.height = window.innerHeight * 0.90;

        var chart = new google.visualization.LineChart(document.getElementById('chart'));
        chart.draw(app.data.graphConfig.data, app.data.graphConfig.options);
        // chart.draw($scope.graphData, google.charts.Line.convertOptions(options));    
    }
}

window.addEventListener('resize', function(e){
    if(app.data.graphConfig){
        app.fun.drawGraph();
    }
})
Run Code Online (Sandbox Code Playgroud)

据我所知,这应该只是网页上的javascript可以访问的“窗口”。

pay*_*ne8 3

看起来您引用的相关 Javascript 正在主进程中运行,而不是在渲染器进程中运行。如果将引用的代码window移至 html 中的脚本标记中,则不应看到相同的问题。

至于需要 html 页面中的文件,我希望它也能像在脚本标签中一样工作。但我可能会弄错。