Tag - electron

electron    2019-07-31 20:54:20    367    0    0

按照官方文档进行操作,执行 npm start 时提示不明白 start 是什么操作,在package.json内添加 start 定义:

  1. "scripts": {
  2. "start": "electron ."
  3. }

再次尝试,哒哒~成功

然后页面上各个版本信息显示不出来,比较官方demo,创建窗口时需要设置preload.js:

  1. win = new BrowserWindow({
  2. width: 800,
  3. height: 600,
  4. webPreferences: {
  5. preload: path.join(__dirname, 'preload.js')
  6. }
  7. });

preload.js 文件内容:

  1. // All of the Node.js APIs are available in the preload process.
  2. // It has the same sandbox as a Chrome extension.
  3. window.addEventListener('DOMContentLoaded', () => {
  4. const replaceText = (selector, text) => {
  5. const element = document.getElementById(selector)
  6. if (element) element.innerText = text
  7. }
  8. for (const type of ['chrome', 'node', 'electron']) {
  9. replaceText(`${type}`, process.versions[type])
  10. }
  11. })

index.html 文件增加标签id:

  1. We are using node <span id="node"></span>,
  2. Chrome <span id="chrome"></span>,
  3. and Electron <span id="electron"></span>.

再次执行,显示成功。

title