{"id":5673,"date":"2023-10-17T17:25:18","date_gmt":"2023-10-17T09:25:18","guid":{"rendered":"https:\/\/www.yimenyun.ltd\/ezhan\/?p=5673"},"modified":"2023-10-17T17:25:18","modified_gmt":"2023-10-17T09:25:18","slug":"h5%e6%a1%8c%e9%9d%a2%e5%ba%94%e7%94%a8%e5%bc%80%e5%8f%91%e6%8e%a8%e8%8d%90%e4%b8%80%e9%97%a8%e5%bc%80%e5%8f%91%e5%b9%b3%e5%8f%b0","status":"publish","type":"post","link":"https:\/\/www.yimenyun.ltd\/ezhan\/5673\/","title":{"rendered":"h5\u684c\u9762\u5e94\u7528\u5f00\u53d1\u63a8\u8350\u4e00\u95e8\u5f00\u53d1\u5e73\u53f0"},"content":{"rendered":"<p>H5\u684c\u9762\u5e94\u7528\u5f00\u53d1\u662f\u76ee\u524d\u4e92\u8054\u7f51\u9886\u57df\u975e\u5e38\u70ed\u95e8\u7684\u6280\u672f\uff0c\u5b83\u80fd\u591f\u8ba9\u7f51\u9875\u5e94\u7528\u5728\u684c\u9762\u4e0a\u8fd0\u884c\uff0c\u5177\u6709\u8de8\u5e73\u53f0\u3001\u6613\u7ef4\u62a4\u7b49\u4f18\u70b9\u3002\u4e0b\u9762\u5c06\u8be6\u7ec6\u4ecb\u7ecdH5\u684c\u9762\u5e94\u7528\u5f00\u53d1\u7684\u539f\u7406\u548c\u5177\u4f53\u5b9e\u73b0\u65b9\u6cd5\u3002<\/p>\n<p>\u4e00\u3001\u539f\u7406<\/p>\n<p>H5\u684c\u9762\u5e94\u7528\u5f00\u53d1\u7684\u539f\u7406\u4e3b\u8981\u662f\u901a\u8fc7Ele<a href=\"https:\/\/www.yimenapp.cn\/fengzhuang-2002.html\">sdk\u662f\u4e00\u6bb5\u4ee3\u7801\u5417<\/a>ctron\u8fd9\u4e2a\u5f00\u6e90\u6846\u67b6\u6765\u5b9e\u73b0\u3002Electron\u662f\u7531GitHub\u5f00\u53d1\u7684\u4e00\u4e2a\u8de8\u5e73\u53f0\u684c\u9762\u5e94\u7528\u5f00\u53d1\u5de5\u5177\uff0c\u5b83\u57fa\u4e8eChromium\u548cNode.js\uff0c\u53ef\u4ee5\u4f7f\u7528HTML\u3001CSS\u548cJavaScript\u7b49\u7f51\u9875\u6280\u672f\u6765\u5f00\u53d1\u684c\u9762\u5e94\u7528\u3002\u5177\u4f53\u7684\u539f\u7406\u5982\u4e0b\uff1a<\/p>\n<p>1. Electron\u4f7f\u7528Chromium\u4f5c\u4e3a\u6e32\u67d3\u5f15\u64ce\uff0c\u5c06\u7f51\u9875\u5d4c\u5165\u5230\u684c\u9762\u5e94\u7528\u4e2d\uff0c\u5b9e\u73b0\u4e86\u4e0e\u6d4f\u89c8\u5668\u76f8\u540c\u7684\u7f51\u9875\u6e32\u67d3\u80fd\u529b\u3002<\/p>\n<p>2. Electron\u4f7f\u7528Node.js\u4f5c\u4e3a\u540e\u7aef\uff0c\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528Node.js\u7684API\u6765\u5b9e\u73b0\u8bbf\u95ee\u672c\u5730\u6587\u4ef6\u3001\u64cd\u4f5c\u7cfb\u7edf\u7b49\u529f\u80fd\u3002<\/p>\n<p>3. Electron\u63d0\u4f9b\u4e86\u4e00\u4e9b\u684c\u9762\u5e94\u7528\u7684API\uff0c\u5982\u5bf9\u8bdd\u6846\u3001\u83dc\u5355\u3001\u6258\u76d8\u7b49\uff0c\u53ef\u4ee5\u65b9\u4fbf\u5730\u5b9e\u73b0\u684c\u9762\u5e94\u7528\u7684\u4ea4\u4e92\u548c\u754c\u9762\u8bbe\u8ba1\u3002<\/p>\n<p>\u4e8c\u3001\u5177\u4f53\u5b9e\u73b0\u65b9\u6cd5<\/p>\n<p>1. \u5b89\u88c5Electron<\/p>\n<p>\u9996\u5148\u9700\u8981\u5b89\u88c5Electron\uff0c\u53ef\u4ee5\u901a\u8fc7npm\u5b89\u88c5\uff0c\u547d\u4ee4\u5982\u4e0b\uff1a<\/p>\n<p>&#8220;`<\/p>\n<p>npm install electron &#8211;save-dev<\/p>\n<p>&#8220;`<\/p>\n<p>2. \u521b\u5efaElectron\u5e94\u7528<\/p>\n<p>\u5728\u9879\u76ee\u76ee\u5f55\u4e0b\u521b\u5efa\u4e00\u4e2amain.js\u6587\u4ef6\uff0c\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<p>&#8220;`<\/p>\n<p>const { app, BrowserWindow } = require(&#8216;electron&#8217;)<\/p>\n<p>function createWindow () {<\/p>\n<p>  \/\/ \u521b\u5efa\u6d4f\u89c8\u5668\u7a97\u53e3<\/p>\n<p>  let win = new BrowserWindow({<\/p>\n<p>    width: 800,<\/p>\n<p>    height: 600,<\/p>\n<p>    webPreferences: {<\/p>\n<p>      nodeIntegra<\/p>\n<p><figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/i.yimenyun.net\/2023-03\/17\/15\/18745863695.jpg\" \/><\/figure>\n<\/p>\n<p>tion: true<\/p>\n<p>    }<\/p>\n<p>  })<\/p>\n<p>  \/\/ \u52a0\u8f7dindex.html\u6587\u4ef6<\/p>\n<p>  win.loadFile(&#8216;index.html&#8217;)<\/p>\n<p>}<\/p>\n<p>app.whenReady().then(() =&gt; {<\/p>\n<p>  createWindow()<\/p>\n<p>  app.on(&#8216;activate&#8217;, () =&gt; {<\/p>\n<p>    if (BrowserWindow.getAllWindows().length === 0) {<\/p>\n<p>      createWindow()<\/p>\n<p>    }<\/p>\n<p>  })<\/p>\n<p>})<\/p>\n<p>app.on(&#8216;window-all-closed&#8217;, () =&gt; {<\/p>\n<p>  if (process.platform !== &#8216;darwin&#8217;) {<\/p>\n<p>    app.quit()<\/p>\n<p>  }<\/p>\n<p>})<\/p>\n<p>&#8220;`<\/p>\n<p>\u4e0a\u8ff0\u4ee3\u7801\u521b\u5efa\u4e86\u4e00\u4e2aElectron\u5e94\u7528\u7a97\u53e3\uff0c\u5e76\u52a0\u8f7d\u4e86index.html\u6587\u4ef6\u3002\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0cwebPreferences\u4e2d\u7684nodeIntegration\u5c5e\u6027\u5fc5\u987b\u8bbe\u7f6e\u4e3atr<a href=\"https:\/\/www.yimenapp.cn\/fengzhuang-3597.html\">\u5e94\u7528\u5236\u4f5capp<\/a>ue\uff0c\u8fd9\u6837\u624d\u80fd\u591f\u5728\u9875\u9762\u4e2d\u4f7f\u7528Node.js\u7684API\u3002<\/p>\n<p>3. \u7f16\u5199\u7f51\u9875\u5e94\u7528<\/p>\n<p>\u5728\u9879\u76ee\u76ee\u5f55\u4e0b\u521b\u5efa\u4e00\u4e2aindex.html\u6587\u4ef6\uff0c\u7f16\u5199\u7f51\u9875\u5e94\u7528\u7684\u4ee3\u7801\uff0c\u5982\u4e0b\uff1a<\/p>\n<p>&#8220;`<\/p>\n<\/p>\n<p>\n<p>\n<p>    <title>Hello World!<\/title><\/p>\n<\/p>\n<p>\n<p>    Hello World!<\/p>\n<\/p>\n<p>&#8220;`<\/p>\n<p>4. \u8fd0\u884cElectron\u5e94\u7528<\/p>\n<p>\u5728\u547d\u4ee4\u884c\u4e2d\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\uff0c\u542f\u52a8Electron\u5e94\u7528\uff1a<\/p>\n<p>&#8220;`<\/p>\n<p>electron .<\/p>\n<p>&#8220;`<\/p>\n<p>\u8fd9\u6837\u5c31\u53ef\u4ee5\u5728\u684c\u9762\u4e0a\u770b\u5230\u4e00\u4e2aElectron\u5e94\u7528\u7a97\u53e3\uff0c\u5e76\u663e\u793a\u4e86\u201cHello World!\u201d\u7684\u7f51\u9875\u5185\u5bb9\u3002<\/p>\n<p>\u603b\u7ed3<\/p>\n<p>H5\u684c\u9762\u5e94\u7528\u5f00\u53d1\u662f\u76ee\u524d\u975e\u5e38\u6d41\u884c\u7684\u6280\u672f\uff0c\u53ef\u4ee5\u8ba9\u7f51\u9875\u5e94\u7528\u5728\u684c\u9762\u4e0a\u8fd0\u884c\uff0c\u5177\u6709\u8de8\u5e73\u53f0\u3001\u6613\u7ef4\u62a4\u7b49\u4f18\u70b9\u3002\u901a\u8fc7Electron\u6846\u67b6\uff0c\u53ef\u4ee5\u65b9\u4fbf\u5730\u5b9e\u73b0H5\u684c\u9762\u5e94\u7528\u5f00\u53d1\uff0c\u5177\u4f53\u5b9e\u73b0\u65b9\u6cd5\u5c31\u662f\u5b89\u88c5Electron\uff0c\u521b\u5efaElectron\u5e94\u7528\uff0c\u7f16\u5199\u7f51\u9875\u5e94\u7528\uff0c\u6700\u540e\u8fd0\u884cElectron\u5e94\u7528\u5373\u53ef\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>H5\u684c\u9762\u5e94\u7528\u5f00\u53d1\u662f\u76ee\u524d\u4e92\u8054\u7f51\u9886\u57df\u975e\u5e38\u70ed\u95e8\u7684\u6280\u672f\uff0c\u5b83\u80fd\u591f\u8ba9\u7f51\u9875\u5e94\u7528\u5728\u684c\u9762\u4e0a\u8fd0\u884c\uff0c\u5177\u6709\u8de8\u5e73\u53f0\u3001\u6613\u7ef4\u62a4\u7b49\u4f18\u70b9\u3002\u4e0b\u9762\u5c06\u8be6\u7ec6\u4ecb\u7ecdH5\u684c\u9762\u5e94\u7528\u5f00\u53d1\u7684\u539f\u7406\u548c\u5177\u4f53\u5b9e\u73b0\u65b9\u6cd5\u3002\u4e00\u3001\u539f\u7406H5\u684c\u9762\u5e94\u7528\u5f00\u53d1\u7684\u539f\u7406\u4e3b\u8981\u662f\u901a\u8fc7E<\/p>\n","protected":false},"author":23,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[10391,1664,10390,2068,135],"topic":[],"class_list":["post-5673","post","type-post","status-publish","format-standard","hentry","category-appkaifa","tag-vueapp","tag-1664","tag-app","tag-2068","tag-135"],"_links":{"self":[{"href":"https:\/\/www.yimenyun.ltd\/ezhan\/wp-json\/wp\/v2\/posts\/5673","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.yimenyun.ltd\/ezhan\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.yimenyun.ltd\/ezhan\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.yimenyun.ltd\/ezhan\/wp-json\/wp\/v2\/users\/23"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yimenyun.ltd\/ezhan\/wp-json\/wp\/v2\/comments?post=5673"}],"version-history":[{"count":0,"href":"https:\/\/www.yimenyun.ltd\/ezhan\/wp-json\/wp\/v2\/posts\/5673\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.yimenyun.ltd\/ezhan\/wp-json\/wp\/v2\/media?parent=5673"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yimenyun.ltd\/ezhan\/wp-json\/wp\/v2\/categories?post=5673"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yimenyun.ltd\/ezhan\/wp-json\/wp\/v2\/tags?post=5673"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.yimenyun.ltd\/ezhan\/wp-json\/wp\/v2\/topic?post=5673"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}