{"id":3050,"date":"2023-08-16T15:47:11","date_gmt":"2023-08-16T07:47:11","guid":{"rendered":"https:\/\/www.yimenyun.cn\/emen\/?p=3050"},"modified":"2023-08-16T15:47:11","modified_gmt":"2023-08-16T07:47:11","slug":"html%e6%89%93%e5%8c%85%e7%94%b5%e8%84%91%e6%a1%8c%e9%9d%a2%e5%ba%94%e7%94%a8%e5%b8%b8%e7%94%a8%e5%b7%a5%e5%85%b7%e6%8e%a8%e8%8d%90","status":"publish","type":"post","link":"https:\/\/www.yimenyun.cn\/emen\/3050\/","title":{"rendered":"html\u6253\u5305\u7535\u8111\u684c\u9762\u5e94\u7528\u5e38\u7528\u5de5\u5177\u63a8\u8350"},"content":{"rendered":"
HTM\u5c06\u7f51\u9875\u7248\u6253\u5305\u6210exe\u7684\u8f6f\u4ef6<\/a>L\u6253\u5305\u6210\u7535\u8111\u684c\u9762\u5e94\u7528\u7684\u6280\u672f\u88ab\u79f0\u4e3aElectron\u3002Electron\u662f\u7531GitHub\u5f00\u53d1\u7684\u8de8\u5e73\u53f0\u6846\u67b6\uff0c\u901a\u8fc7\u4f7f\u7528Electron\u53ef\u4ee5\u5c06HTML\u3001CSS\u548cJavaScript\u7b49Web\u6280\u672f\u6253\u5305\u6210\u684c\u9762\u5e94\u7528\u7a0b\u5e8f\uff0c\u800c\u65e0\u9700\u4e86\u89e3\u5e95\u5c42\u64cd\u4f5c\u7cfb\u7edf\u7684API\u3002<\/p>\n Electron\u7684\u539f\u7406\u662f\u5c06Web\u5e94\u7528\u7a0b\u5e8f\u548cNode.js\u8fd0\u884c\u65f6\u6253\u5305\u6210\u4e00\u4e2a\u53ef\u6267\u884c\u6587\u4ef6\uff0c\u5e76\u5728\u5e95\u5c42\u4f7f\u7528Chromium\u6d4f\u89c8\u5668\u6765\u6e32\u67d3\u5e94\u7528\u7a0b\u5e8f\u7684\u7528\u6237\u754c\u9762\u3002\u8fd9\u4f7f\u5f97\u5f00\u53d1\u8005\u53ef\u4ee5\u4f7f\u7528\u4e00\u5957\u7edf\u4e00\u7684\u6280\u672f\u6808\u6765\u5f00\u53d1\u8de8\u5e73\u53f0\u7684\u684c\u9762\u5e94\u7528\u7a0b\u5e8f\uff0c\u800c\u65e0\u9700\u4e3a\u4e0d\u540c\u64cd\u4f5c\u7cfb\u7edf\u7f16\u5199\u4e0d\u540c\u7684\u4ee3\u7801\u3002<\/p>\n \u4e0b\u9762\u4ecb\u7ecd\u4e00\u4e0b\u5982\u4f55\u4f7f\u7528Electron\u5c06HTML\u6253\u5305\u6210\u684c\u9762\u5e94\u7528\u3002<\/p>\n 1. \u5b89\u88c5Electron<\/p>\n \u9996\u5148\uff0c\u9700\u8981\u5728\u672c\u5730\u5b89\u88c5Electron\u3002\u53ef\u4ee5\u4f7f\u7528npm\u547d\u4ee4\u884c\u5de5\u5177\u6765\u5b89\u88c5Electron\uff0c\u547d\u4ee4\u5982\u4e0b\uff1a<\/p>\n “`<\/p>\n npm install -g electron<\/p>\n “`<\/p>\n 2. \u521b\u5efaElectron\u9879\u76ee<\/p>\n \u5728\u672c\u5730\u521b\u5efa\u4e00\u4e2aElectron\u9879\u76ee\uff0c\u53ef\u4ee5\u4f7f\u7528Electron\u63d0\u4f9b\u7684CLI\u5de5\u5177\u6765\u521b\u5efa\uff0c\u547d\u4ee4\u5982\u4e0b\uff1a<\/p>\n “`<\/p>\n electron-forge init my-electron-app<\/p>\n “`<\/p>\n \u8fd9\u5c06\u521b\u5efa\u4e00\u4e2a\u540d\u4e3amy-electron-app\u7684\u9879\u76ee\uff0c\u5e76\u5728\u5176\u4e2d\u5305\u542b\u5fc5\u8981\u7684\u6587\u4ef6\u548c\u76ee\u5f55\u3002<\/p>\n 3. \u7f16\u5199HTML\u4ee3\u7801<\/p>\n \u5728\u9879\u76ee\u76ee\u5f55\u4e2d\u521b\u5efa\u4e00\u4e2aindex.html\u6587\u4ef6\uff0c\u5e76\u5728\u5176\u4e2d\u7f16\u5199HTML\u4ee3\u7801\u3002\u8fd9\u5c06\u662f\u5e94\u7528\u7a0b\u5e8f\u7684\u4e3b\u754c\u9762\u3002<\/p>\n 4. \u7f16\u5199\u4e3b\u8fdb\u7a0b\u4ee3\u7801<\/p>\n \u5728\u9879\u76ee\u76ee\u5f55\u4e2d\u521b\u5efa\u4e00\u4e2amain.js\u6587\u4ef6\uff0c\u5e76\u5728\u5176\u4e2d\u7f16\u5199\u4e3b\u8fdb\u7a0b\u4ee3\u7801\u3002\u4e3b\u8fdb\u7a0b\u662fElectron\u5e94\u7528\u7a0b\u5e8f\u7684\u6838\u5fc3\uff0c\u5b83\u7ba1\u7406\u5e94\u7528\u7a0b\u5e8f\u7684\u751f\u547d\u5468\u671f\u3001\u7a97\u53e3\u3001\u83dc\u5355\u7b49\u7b49\u3002<\/p>\n \u4e3b\u8fdb\u7a0b\u4ee3\u7801\u793a\u4f8b\uff1a<\/p>\n “`<\/p>\n const { app, BrowserWindow } = require(‘electron’)<\/p>\n function createWindow () {<\/p>\n const win = new BrowserWindow({<\/p>\n width: 800,<\/p>\n height: 600,<\/p>\n webPreferences: {<\/p>\n nodeIntegration: true<\/p>\n }<\/p>\n })<\/p>\n win.loadFile(‘index.html’)<\/p>\n }<\/p>\n app.whenReady().then(() => {<\/p>\n createWindow()<\/p>\n app.on(‘activate’, () => {<\/p>\n if (BrowserWindow.getAllWindows().length === 0) {<\/p>\n createWindow()<\/p>\n }<\/p>\n })<\/p>\n })<\/p>\n app.on(‘window-all-closed’, () => {<\/p>\n if (process.platform !== ‘darwin’) {<\/p>\n app.quit()<\/p>\n }<\/p>\n })<\/p>\n “`<\/p>\n \u8fd9\u6bb5\u4ee3\u7801\u521b\u5efa\u4e86\u4e00\u4e2a\u7a97\u53e3\uff0c\u5e76\u5728\u5176\u4e2d\u52a0\u8f7d\u4e86in<\/p>\n dex.html\u6587\u4ef6\u3002<\/p>\n 5. \u6253\u5305\u5e94\u7528\u7a0b\u5e8f<\/p>\n \u6700\u540e\uff0c\u4f7f\u7528Electron\u63d0\u4f9b\u7684\u6253\u5305\u5de5\u5177\u5c06\u5e94\u7528\u7a0b\u5e8f\u6253\u5305\u6210\u53ef\u6267\u884c\u6587\u4ef6\u3002\u53ef\u4ee5\u4f7f\u7528electron-forge\u6765\u6253\u5305\u5e94\u7528\u7a0b\u5e8f\uff0c\u547d\u4ee4\u5982\u4e0b\uff1a<\/p>\n “`<\/p>\n electron-forge make<\/p>\n “`<\/p>\n \u8fd9\u5c06\u5728\u9879\u76ee\u76ee\u5f55\u4e2d\u521b\u5efa\u4e00\u4e2aout\u76ee\u5f55\uff0c\u5e76\u5728\u5176\u4e2d\u5305\u542b\u53ef\u6267\u884c\u6587\u4ef6\u3002<\/p>\n \u603b\u7ed3<\/p>\n \u4f7f\u7528Electron\u5c06HTML\u6253\u5305\u6210\u684c\u9762\u5e94\u7528\u7a0b\u5e8f\u975e\u5e38\u7b80\u5355\uff0c\u53ea\u9700\u8981\u9075\u5faa\u4e0a\u8ff0\u6b65\u9aa4\u5373\u53ef\u3002Electron\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684API\u548c\u5de5\u5177\uff0c\u4f7f\u5f97\u5f00\u53d1\u8005\u53ef\u4ee5\u8f7b\u677e\u5730\u521b\u5efa\u8de8\u5e73\u53f0\u7684\u5982\u4f55\u5c06\u6587\u4ef6\u6253\u5305\u6210exe<\/a>\u684c\u9762\u5e94\u7528\u7a0b\u5e8f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":" HTML\u6253\u5305\u6210\u7535\u8111\u684c\u9762\u5e94\u7528\u7684\u6280\u672f\u88ab\u79f0\u4e3aElectron\u3002Electron\u662f\u7531GitHub\u5f00\u53d1\u7684\u8de8\u5e73\u53f0\u6846\u67b6\uff0c\u901a\u8fc7\u4f7f\u7528Electron\u53ef\u4ee5\u5c06HTML\u3001CSS\u548cJavaScript\u7b49Web\u6280\u672f\u6253\u5305\u6210\u684c\u9762\u5e94<\/p>\n","protected":false},"author":7,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[6213,6211,29,6212,12],"topic":[],"class_list":["post-3050","post","type-post","status-publish","format-standard","hentry","category-exekf","tag-htmlexe","tag-viexe","tag-29","tag-6212","tag-12"],"_links":{"self":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/posts\/3050","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/comments?post=3050"}],"version-history":[{"count":0,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/posts\/3050\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/media?parent=3050"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/categories?post=3050"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/tags?post=3050"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/topic?post=3050"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}<\/figure>\n<\/p>\n