{"id":15711,"date":"2024-01-16T15:43:28","date_gmt":"2024-01-16T07:43:28","guid":{"rendered":"https:\/\/www.zhidianwl.net\/zhidianwl\/?p=15711"},"modified":"2024-01-16T15:43:28","modified_gmt":"2024-01-16T07:43:28","slug":"vue%e6%89%93%e5%8c%85exe%e6%93%8d%e4%bd%9c%e6%b5%81%e7%a8%8b%e4%bb%8b%e7%bb%8d","status":"publish","type":"post","link":"https:\/\/www.zhidianwl.net\/zhidianwl\/2024\/01\/16\/vue%e6%89%93%e5%8c%85exe%e6%93%8d%e4%bd%9c%e6%b5%81%e7%a8%8b%e4%bb%8b%e7%bb%8d\/","title":{"rendered":"vue\u6253\u5305exe\u64cd\u4f5c\u6d41\u7a0b\u4ecb\u7ecd"},"content":{"rendered":"
Vue\u662f\u4e00\u79cd\u73b0\u4ee3\u5316\u7684JavaScript\u6846\u67b6\uff0c\u7528\u4e8e\u6784\u5efa\u5355\u9875\u9762\u5e94\u7528\u7a0b\u5e8f\uff08SPA\uff09\u548c\u5176\u4ed6\u590d\u6742\u7684Web\u5e94\u7528\u7a0b\u5e8f\u3002Vue\u7684\u4e3b\u8981\u7279\u70b9\u662f\u5176\u8f7b\u91cf\u7ea7\uff0c\u6613\u4e8e\u5b66\u4e60\u548c\u4f7f\u7528\u3002Vue<\/p>\n
\u7684\u751f\u6001\u7cfb\u7edf\u4e5f\u975e\u5e38\u4e30\u5bcc\uff0c\u6709\u8bb8\u591a\u63d2\u4ef6\u548c\u5de5\u5177\u53ef\u4ee5\u5e2e\u52a9\u5f00\u53d1\u4eba\u5458\u66f4\u597d\u5730\u6784\u5efa\u548c\u90e8\u7f72\u5e94\u7528\u7a0b\u5e8f\u3002\u672c\u6587\u5c06\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528Electron\u5c06Vue\u5e94\u7528\u7a0b\u5e8f\u6253\u5305\u4e3a\u53ef\u6267\u884c\u6587\u4ef6\u3002<\/p>\n Electron\u662f\u4e00\u4e2a\u57fa\u4e8eNode.js\u548cChromium\u7684\u6846\u67b6\uff0c\u7528\u4e8e\u6784\u5efa\u8de8\u5e73\u53f0\u684c\u9762\u5e94\u7528\u7a0b\u5e8f\u3002Electron\u63d0\u4f9b\u4e86\u4e00\u4e2a\u5feb\u901f\u548c\u7b80\u5355\u7684\u65b9\u6cd5\u6765\u5c06Web\u5e94\u7528\u7a0b\u5e8f\u8f6c\u6362\u4e3a\u684c\u9762\u5e94\u7528\u7a0b\u5e8f\uff0c\u5e76\u652f\u6301\u5404\u79cd\u4e0d\u540c\u7684\u64cd\u4f5c\u7cfb\u7edf\uff0c\u5305\u62ecWindows\uff0cMac\u548cLinux\u3002<\/p>\n \u4e0b\u9762\u662f\u5c06Vue\u5e94\u7528\u7a0b\u5e8f\u6253\u5305\u4e3a\u53ef\u6267\u884c\u6587\u4ef6\u7684\u6b65\u9aa4\uff1a<\/p>\n 1. \u5b89\u88c5Electron<\/p>\n \u9996\u5148\uff0c\u9700\u8981\u5b89\u88c5Electron\u3002\u53ef\u4ee5\u4f7f\u7528npm\u6765\u5b89\u88c5Electron\uff0c\u547d\u4ee4\u5982\u4e0b\uff1a<\/p>\n “`<\/p>\n npm install electron –save-dev<\/p>\n “`<\/p>\n 2. \u521b\u5efaElectron\u4e3b\u8fdb\u7a0b<\/p>\n \u5728Vue\u5e94\u7528\u7a0b\u5e8f\u7684\u6839\u76ee\u5f55\u4e2d\uff0c\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a\u201cmain.js\u201d\u7684\u6587\u4ef6\u3002\u8fd9\u4e2a\u6587\u4ef6\u5c06\u662fElectron\u5e94\u7528\u7a0b\u5e8f\u7684\u4e3b\u8fdb\u7a0b\u3002\u5728\u8fd9\u4e2a\u6587\u4ef6\u4e2d\uff0c\u9700\u8981\u5f15\u5165Electron\u6a21\u5757\u5e76\u521b\u5efa\u4e00\u4e2aElectron\u5e94\u7528\u7a0b\u5e8f\u5b9e\u4f8b\u3002\u4e0b\u9762\u662f\u4e00\u4e2a\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 “`<\/p>\n \u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u521b\u5efa\u4e86\u4e00\u4e2a\u540d\u4e3a\u201cwin\u201d\u7684BrowserWindow\u5b9e\u4f8b\uff0c\u5e76\u52a0\u8f7d\u4e86Vue\u5e94\u7528\u7a0b\u5e8f\u7684\u201cindex.html\u201d\u6587\u4ef6\u3002\u8fd9\u4e2a\u6587\u4ef6\u5e94\u8be5\u4f4d\u4e8eVue\u5e94\u7528\u7a0b\u5e8f\u7684\u201cdist\u201d\u76ee\u5f55\u4e2d\u3002<\/p>\n 3. \u4fee\u6539Vue\u5e94\u7528windows2022<\/a>\u7a0b\u5e8f\u7684\u5165\u53e3\u6587\u4ef6<\/p>\n \u5728Vue\u5e94\u7528\u7a0b\u5e8f\u7684\u5165\u53e3\u6587\u4ef6\u4e2d\uff0c\u9700\u8981\u6dfb\u52a0\u4ee5\u4e0b\u4ee3\u7801\uff1a<\/p>\n “`<\/p>\n if (window.process && window.process.type === ‘renderer’) {<\/p>\n window.require = require;<\/p>\n }<\/p>\n “`<\/p>\n \u8fd9\u4e2a\u4ee3\u7801\u7247\u6bb5\u5c06\u5141\u8bb8Vue\u5e94\u7528\u7a0b\u5e8f\u5728Electron\u4e2d\u8fd0\u884c\uff0c\u5e76\u4f7f\u5176\u80fd\u591f\u8bbf\u95eeNode.js\u6a21\u5757\u3002<\/p>\n 4. \u4fee\u6539Vue\u5e94\u7528\u7a0b\u5e8f\u7684\u6253\u5305\u914d\u7f6e<\/p>\n \u5728Vue\u5e94\u7528\u7a0b\u5e8f\u7684\u201cpackage.json\u201d\u6587\u4ef6\u4e2d\uff0c\u9700\u8981\u6dfb\u52a0\u4ee5\u4e0b\u4ee3\u7801\uff1a<\/p>\n “`<\/p>\n “build”: {<\/p>\n “electronVersion”: “11.2.3”,<\/p>\n “builder”: {<\/p>\n “appId”: “com.example.myapp”,<\/p>\n “mac”: {<\/p>\n “target”: “dmg”<\/p>\n },<\/p>\n “win”: {<\/p>\n “target”: “nsis”<\/p>\n }<\/p>\n }<\/p>\n }<\/p>\n “`<\/p>\n \u8fd9\u4e2a\u4ee3\u7801\u7247\u6bb5\u5c06\u6307\u793aElectron Builder\u5982\u4f55\u5c06Vue\u5e94\u7528\u7a0b\u5e8f\u6253\u5305\u4e3a\u53ef\u6267\u884c\u6587\u4ef6\u3002\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u6307\u5b9a\u4e86\u5e94\u7528\u7a0b\u5e8f\u7684ID\u548c\u5728Mac\u548cWindows\u4e0a\u4f7f\u7528\u7684\u76ee\u6807\u683c\u5f0f\u3002<\/p>\n 5. \u6253\u5305Vue\u5e94\u7528\u7a0b\u5e8f<\/p>\n \u5728\u7ec8\u7aef\u4e2d\uff0c\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u6765\u6253\u5305Vue\u5e94\u7528\u7a0b\u5e8f\uff1a<\/p>\n “`<\/p>\n npm run build<\/p>\n npm run electron:build<\/p>\n “`<\/p>\n \u7b2c\u4e00\u4e2a\u547d\u4ee4\u5c06\u751f\u6210Vue\u5e94\u7528\u7a0b\u5e8f\u7684\u6784\u5efa\u6587\u4ef6\uff0c\u5c06\u5b83\u4eec\u653e\u7f6e\u5728\u201cdist\u201d\u76ee\u5f55\u4e2d\u3002\u7b2c\u4e8c\u4e2a\u547d\u4ee4\u5c06\u4f7f\u7528Electron Builder\u5c06Vue\u5e94\u7528\u7a0b\u5e8f\u6253\u5305\u4e3a\u53ef\u6267\u884c\u6587\u4ef6\u3002\u6253\u5305\u540e\u7684\u6587\u4ef6\u5c06\u4f4d\u4e8e\u201cdist_electron\u201d\u76ee\u5f55\u4e2d\u3002<\/p>\n \u603b\u7ed3<\/p>\n \u5c06Vue\u5e94\u7528\u7a0b\u5e8f\u6253\u5305\u4e3a\u53ef\u6267\u884c\u6587\u4ef6\u5e76\u4e0d\u56f0\u96be\uff0c\u53ea\u9700\u9075\u5faa\u4ee5\u4e0a\u6b65\u9aa4\u5373\u53ef\u3002\u4f7f\u7528Electron\u548cElectron Builder\u53ef\u4ee5\u8f7b\u677e\u5730\u5c06Web\u5e94\u7528\u7a0b\u5e8f\u8f6c\u6362\u4e3a\u684c\u9762\u5e94\u5236\u4f5c\u6210\u7ee9\u5355\u8f6f\u4ef6<\/a>\u7528\u7a0b\u5e8f\uff0c\u5e76\u5728\u4e0d\u540c\u7684\u64cd\u4f5c\u7cfb\u7edf\u4e0a\u8fdb\u884c\u90e8\u7f72\u3002<\/p>\n","protected":false},"excerpt":{"rendered":" Vue\u662f\u4e00\u79cd\u73b0\u4ee3\u5316\u7684JavaScript\u6846\u67b6\uff0c\u7528\u4e8e\u6784\u5efa\u5355\u9875\u9762\u5e94\u7528\u7a0b\u5e8f\uff08SPA\uff09\u548c\u5176\u4ed6\u590d\u6742\u7684Web\u5e94\u7528\u7a0b\u5e8f\u3002Vue\u7684\u4e3b\u8981\u7279\u70b9\u662f\u5176\u8f7b\u91cf\u7ea7\uff0c\u6613\u4e8e\u5b66\u4e60\u548c\u4f7f\u7528\u3002Vue\u7684\u751f\u6001\u7cfb\u7edf\u4e5f\u975e\u5e38\u4e30\u5bcc\uff0c\u6709\u8bb8\u591a\u63d2\u4ef6\u548c\u5de5\u5177\u53ef\u4ee5<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[19567,19517,24,116,12],"topic":[],"class_list":["post-15711","post","type-post","status-publish","format-standard","hentry","category-zhuomianruanjian","tag-mindexe","tag-windows10","tag-24","tag-116","tag-12"],"_links":{"self":[{"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/posts\/15711","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/comments?post=15711"}],"version-history":[{"count":1,"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/posts\/15711\/revisions"}],"predecessor-version":[{"id":15736,"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/posts\/15711\/revisions\/15736"}],"wp:attachment":[{"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/media?parent=15711"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/categories?post=15711"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/tags?post=15711"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/topic?post=15711"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}<\/figure>\n<\/p>\n