【问题标题】:Node Webkit: Nothing displaying?Node Webkit:什么都没有显示?
【发布时间】:2017-02-18 19:09:38
【问题描述】:

我刚开始使用 Node-Webkit,但遇到了一个问题。我在下面编写了我的代码,但没有显示任何内容,也没有创建我声明要创建的文件。我已经 npm 安装了 fs 和 os 但仍然没有运气。我通过将项目文件夹拖到 nw 可执行文件中来打开它

包.json:

{
    "name": "test-app",
    "main": "index.html",
    "version": "0.1.0",

    "window": {
        "icon": "icon.png",
        "width": "1300",
        "max_width": "2000",
        "min_width": "500",
        "height": "700",
        "max_height": "1500",
        "min_height": "200",
        "position" : "center"
    },

    "bugs": "http://example.com/bugs"
}

索引.html:

<!DOCTYPE html>
<html>
  <head>
    <title>Test</title>
    <link href="https://getbootstrap.com/dist/css/bootstrap.css" rel="stylesheet" type="text/css">

    <script>
        // System Information 
        var os = require('os');

        // File Operations 
        var fs = require('fs');

        // Content
        var content = '';

        // Platform Information 
        content += '[Platform]: ' + os.EOL;
        content += '[OS Type]: ' + os.platform() + os.EOL; // Linux, Darwin Win32, FreeBSD, or SunOs
        content += '[OS Version] ' + os.release() + os.EOL;
        content += '[OS Architecture] ' + os.arch() + os.EOL;
        content += os.EOL;

        // Memory Information
        content += '[Memory]' + os.EOL;
        content += 'Total (Bytes): ' + os.totalmen() + os.EOL;
        content += 'Free (Bytes): ' + os.freenmem() + os.EOL;
        content += 'Free (%): ' + (os.freemem() / os.totalmem() * 100).toFixed(2) + os.EOL;
        content += os.EOL;

        // CPU Information 
        content += '[CPU]: ' + os.EOL;
        content += 'Cores: ' + os.cpus().length + os.EOL;
        content += 'Type: ' + os.cpus[0].model + os.EOL;

        fs.writeFile('./sysinfo.txt', content, function (err) {
          if (err) {
            alert('Error writing file');
          }
          else document.write("Successfully wrote to file.");
        });
    </script>
  </head>
  <body>
  </body>
</html>

【问题讨论】:

    标签: javascript node.js node-webkit


    【解决方案1】:

    请检查您的 index.html 中的拼写错误

    content += '总计(字节):' + os.totalmen() + os.EOL; -- 应该是 os.totalmem()

    content += '免费(字节):' + os.freenmem() + os.EOL; -- 应该是 os.freemem()

    和 content += '类型:' + os.cpus[0].model + os.EOL; -- os.cpus()[0].model

    【讨论】:

    • 前段时间修复了所有的拼写错误,还是不行。
    • 你想如何运行它?在项目文件夹中运行 nw
    • 是的,它显示一个空白页。
    【解决方案2】:

    替换...

    os.cpus[0].model

    随着...

    os.cpus()[0].model
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-18
      • 1970-01-01
      • 2023-04-04
      • 1970-01-01
      • 1970-01-01
      • 2020-12-21
      相关资源
      最近更新 更多