{"id":15835,"date":"2024-01-16T15:43:26","date_gmt":"2024-01-16T07:43:26","guid":{"rendered":"https:\/\/www.yimenyun.cn\/emen\/?p=15835"},"modified":"2024-01-16T15:43:26","modified_gmt":"2024-01-16T07:43:26","slug":"vue%e6%89%93%e5%8c%85exe%e8%b7%a8%e5%9f%9f%e6%80%8e%e4%b9%88%e5%a4%84%e7%90%86","status":"publish","type":"post","link":"https:\/\/www.yimenyun.cn\/emen\/15835\/","title":{"rendered":"vue\u6253\u5305exe\u8de8\u57df\u600e\u4e48\u5904\u7406?"},"content":{"rendered":"

Vue\u662f\u4e00\u6b3e\u975e\u5e38\u6d41\u884c\u7684JavaScript\u6846\u67b6\uff0c\u5b83\u53ef\u4ee5\u5e2e\u52a9\u5f00\u53d1\u8005\u5feb\u901f\u6784\u5efa\u73b0\u4ee3\u5316\u7684Web\u5e94\u7528\u7a0b\u5e8f\u3002\u5728\u5f00\u53d1Vue\u5e94\u7528\u7a0b\u5e8f\u65f6\uff0c\u6211\u4eec\u901a\u5e38\u4f1a\u4f7f\u7528Webpack\u7b49\u6253\u5305\u5de5\u5177\u6765\u5c06\u4ee3\u7801\u6253\u5305\u6210\u4e00\u4e2a\u6216\u591a\u4e2aJavaScript\u6587\u4ef6\uff0c\u4ee5\u4fbf\u5c06\u5176\u90e8\u7f72\u5230\u751f\u4ea7\u73af\u5883\u4e2d\u3002\u4f46\u662f\uff0c\u5f53\u6211\u4eec\u5c1d\u8bd5\u5728\u672c\u5730\u8fd0\u884c\u6253\u5305\u540e\u7684Vue\u5e94\u7528\u7a0b\u5e8f\u65f6\uff0c\u53ef\u80fd\u4f1a\u9047\u5230\u8de8\u57df\u95ee\u9898\u3002\u672c\u6587\u5c06\u4ecb\u7ecd\u5982\u4f55\u89e3\u51b3Vue\u6253\u5305\u540e\u7684\u8de8\u57df\u95ee\u9898\uff0c\u5e76\u4e14\u8ba9\u5e94\u7528\u7a0b\u5e8f\u80fd\u591f\u4ee5.exe\u6587\u4ef6\u7684\u5f62\u5f0f\u5728Windows\u4e0a\u8fd0\u884c\u3002<\/p>\n

\u4e00\u3001\u8de8\u57df\u95ee\u9898<\/p>\n

\u5728Web\u5f00\u53d1\u4e2d\uff0c\u8de8\u57df\u662f\u6307\u5728\u540c\u6e90\u7b56\u7565\u4e0b\uff0c\u4ece\u4e00\u4e2a\u57df\u540d\u7684\u7f51\u9875\u53bb\u8bf7\u6c42\u53e6\u4e00\u4e2a\u57df\u540d\u7684\u8d44\u6e90\uff0c\u8fd9\u79cd\u884c\u4e3a\u662f\u88ab\u6d4f\u89c8\u5668\u7981\u6b62\u7684\u3002\u4f8b\u5982\uff0c\u5728\u672c\u5730\u8fd0\u884cVue\u5e94\u7528\u7a0b\u5e8f\u65f6\uff0c\u5982\u679cVue\u5e94\u7528\u7a0b\u5e8f\u7684\u8d44\u6e90\u6587\u4ef6\uff08\u5982CSS\u3001JS\u6587\u4ef6\uff09\u5b58\u50a8\u5728\u4e00\u4e2a\u4e0d\u540c\u7684\u57df\u540d\u4e0b\uff0c\u90a3\u4e48\u6d4f\u89c8\u5668\u4f1a\u62d2\u7edd\u52a0\u8f7d\u8fd9\u4e9b\u8d44\u6e90\u6587\u4ef6\uff0c\u4ece\u800c\u5bfc\u81f4\u5e94\u7528\u7a0b\u5e8f\u65e0\u6cd5\u6b63\u5e38\u8fd0\u884c\u3002<\/p>\n

\u4e8c\u3001\u89e3\u51b3\u65b9\u6848<\/p>\n

\u4e3a\u4e86\u89e3\u51b3Vue\u6253\u5305\u540e\u7684\u8de8\u57df\u95ee\u9898\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528Electron\u6846\u67b6\u3002Electron\u662f\u4e00\u4e2a\u57fa\u4e8eNode.js\u548cChromium\u7684\u6846\u67b6\uff0c\u5b83\u53ef\u4ee5\u5e2e\u52a9\u6211\u4eec\u521b\u5efa\u8de8\u5e73\u53f0\u7684\u684c\u9762\u5e94\u7528\u7a0b\u5e8f\u3002\u4f7f\u7528Electron\u6846\u67b6\uff0c\u6211\u4eec\u53ef\u4ee5\u5c06Vue\u5e94\u7528\u7a0b\u5e8f\u6253\u5305\u6210\u4e00\u4e2a\u53ef\u6267\u884c\u6587\u4ef6\uff0c\u5e76\u4e14\u8ba9\u5e94\u7528\u7a0b\u5e8f\u80fd\u591f\u5728Windows\u4e0a\u8fd0\u884c\u3002<\/p>\n

1. \u5b89\u88c5Electron<\/p>\n

\u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u5b89\u88c5Electron\u3002\u53ef\u4ee5\u4f7f\u7528npm\u547d\u4ee4\u6765\u5b89\u88c5Electron\uff1a<\/p>\n

“`<\/p>\n

npm install electron –save-dev<\/p>\n

“`<\/p>\n

2. \u521b\u5efaElectron\u5e94\u7528\u7a0b\u5e8f<\/p>\n

\u5728\u5b89\u88c5Electron\u4e4b\u540e\uff0c\u6211\u4eec\u9700\u8981\u521b\u5efa\u4e00\u4e2aElectron\u5e94\u7528\u7a0b\u5e8f\u3002\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528Electron\u5b98\u65b9\u63d0\u4f9b\u7684\u5feb\u901f\u542f\u52a8\u6a21\u677f\u6765\u521b\u5efa\u4e00\u4e2a\u57fa\u672c\u7684E<\/p>\n

<\/figure>\n<\/p>\n

lectron\u5e94\u7528\u7a0b\u5e8f\u3002\u9996\u5148\uff0c\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u4e0b\u8f7d\u6a21\u677f\uff1a<\/p>\n

“`<\/p>\n

npx electron-forge init my-app<\/p>\n

“`<\/p>\n

\u5176\u4e2d\uff0cmy-app\u662f\u5e94\u7528\u7a0b\u5e8f\u7684\u540d\u79f0\u3002\u6267\u884c\u5b8c\u8be5\u547d\u4ee4\u540e\uff0c\u4f1a\u5728\u5f53\u524d\u76ee\u5f55\u4e0b\u521b\u5efa\u4e00\u4e2a\u540d\u4e3amy-app\u7684\u6587\u4ef6\u5939\uff0c\u5176\u4e2d\u5305\u542b\u4e86\u5e94\u7528\u7a0b\u5e8f\u7684\u57fa\u672c\u7ed3\u6784\u3002<\/p>\n

3. \u914d\u7f6eElectron\u5e94\u7528\u7a0b\u5e8f<\/p>\n

\u5728\u521b\u5efa\u597dElectron\u5e94\u7528\u7a0b\u5e8f\u4e4b\u540e\uff0c\u6211\u4eec\u9700\u8981\u914d\u7f6e\u5e94\u7528\u7a0b\u5e8f\uff0c\u4ee5\u4fbf\u8ba9\u5b83\u80fd\u591f\u52a0\u8f7dVue\u5e94\u524d\u7aef\u7f51\u9875\u6253\u5305exe<\/a>\u7528\u7a0b\u5e8f\u3002\u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u5c06Vue\u5e94\u7528\u7a0b\u5e8f\u7684\u6253\u5305\u6587\u4ef6\uff08\u901a\u5e38\u662fdist\u6587\u4ef6\u5939\uff09\u590d\u5236\u5230Electron\u5e94\u7528\u7a0b\u5e8f\u7684\u6839\u76ee\u5f55\u4e0b\u3002\u7136\u540e\uff0c\u5728Electron\u5e94\u7528\u7a0b\u5e8f\u7684main.js\u6587\u4ef6\u4e2d\u6dfb\u52a0\u4ee5\u4e0b\u4ee3\u7801\uff1a<\/p>\n

“`<\/p>\n

const { app, BrowserWindow } = require(‘electron’)<\/p>\n

const path = require(‘path’)<\/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(‘dist\/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

\u8be5\u4ee3\u7801\u4f1a\u521b\u5efa\u4e00\u4e2aElectron\u7a97\u53e3\uff0c\u5e76\u52a0\u8f7dVue\u5e94\u7528\u7a0b\u5e8f\u7684index.html\u6587\u4ef6\u3002\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u7531\u4e8eElectron\u5e94\u7528\u7a0b\u5e8f\u4f7f\u7528\u4e86Node.js\uff0c\u6211\u4eec\u9700\u8981\u5c06webPreferences\u4e2d\u7684nodeIntegration\u8bbe\u7f6e\u4e3atrue\uff0c\u4ee5\u4fbf\u5728Electron\u5e94\u7528\u7a0b\u5e8f\u4e2d\u8fd0\u884cVue\u5e94\u7528\u7a0b\u5e8f\u7684JavaScript\u4ee3\u7801\u3002<\/p>\n

4. \u6253\u5305Electron\u5e94\u7528\u7a0b\u5e8f<\/p>\n

\u5728\u914d\u7f6e\u597dElectron\u5e94\u7528\u7a0b\u5e8f\u4e4b\u540e\uff0c\u6211\u4eec\u9700\u8981\u5c06\u5176\u6253\u5305\u6210\u4e00\u4e2a\u53ef\u6267\u884c\u6587\u4ef6\u3002\u53ef\u4ee5\u4f7f\u7528Electron\u5b98\u65b9\u63d0\u4f9b\u7684electron-packager\u5de5\u5177\u6765\u6253\u5305\u5e94\u7528\u7a0b\u5e8f\u3002\u9996\u5148\uff0c\u4f7f\u7528\u4ee5\u4e0b\u547dhtmlexe\u5e94\u7528\u7a0b\u5e8f\u5f00\u53d1<\/a>\u4ee4\u5b89\u88c5electron-packager\uff1a<\/p>\n

“`<\/p>\n

npm install electron-packager –save-dev<\/p>\n

“`<\/p>\n

\u7136\u540e\uff0c\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u6253\u5305\u5e94\u7528\u7a0b\u5e8f\uff1a<\/p>\n

“`<\/p>\n

npx electron-packager . my-app –platform=win32 –arch=x64 –out=out<\/p>\n

“`<\/p>\n

\u5176\u4e2d\uff0cmy-app\u662f\u5e94\u7528\u7a0b\u5e8f\u7684\u540d\u79f0\uff0c–platform=win32\u8868\u793a\u6253\u5305\u4e3aWindows\u5e73\u53f0\u7684\u5e94\u7528\u7a0b\u5e8f\uff0c–arch=x64\u8868\u793a\u6253\u5305\u4e3a64\u4f4d\u5e94\u7528\u7a0b\u5e8f\uff0c–out=out\u8868\u793a\u5c06\u6253\u5305\u540e\u7684\u5e94\u7528\u7a0b\u5e8f\u8f93\u51fa\u5230out\u6587\u4ef6\u5939\u4e2d\u3002<\/p>\n

5. \u8fd0\u884cElectron\u5e94\u7528\u7a0b\u5e8f<\/p>\n

\u5728\u6253\u5305\u597dElectron\u5e94\u7528\u7a0b\u5e8f\u4e4b\u540e\uff0c\u6211\u4eec\u53ef\u4ee5\u5728Windows\u4e0a\u8fd0\u884c\u5e94\u7528\u7a0b\u5e8f\u3002\u53cc\u51fbout\u6587\u4ef6\u5939\u4e2d\u7684my-app.exe\u6587\u4ef6\u5373\u53ef\u8fd0\u884c\u5e94\u7528\u7a0b\u5e8f\u3002<\/p>\n

\u4e09\u3001\u603b\u7ed3<\/p>\n

\u672c\u6587\u4ecb\u7ecd\u4e86\u5982\u4f55\u89e3\u51b3Vue\u6253\u5305\u540e\u7684\u8de8\u57df\u95ee\u9898\uff0c\u5e76\u4e14\u8ba9\u5e94\u7528\u7a0b\u5e8f\u80fd\u591f\u4ee5.exe\u6587\u4ef6\u7684\u5f62\u5f0f\u5728Windows\u4e0a\u8fd0\u884c\u3002\u901a\u8fc7\u4f7f\u7528Electron\u6846\u67b6\uff0c\u6211\u4eec\u53ef\u4ee5\u5feb\u901f\u521b\u5efa\u8de8\u5e73\u53f0\u7684\u684c\u9762\u5e94\u7528\u7a0b\u5e8f\uff0c\u5e76\u4e14\u8ba9Vue\u5e94\u7528\u7a0b\u5e8f\u80fd\u591f\u5728\u684c\u9762\u5e94\u7528\u7a0b\u5e8f\u4e2d\u8fd0\u884c\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

Vue\u662f\u4e00\u6b3e\u975e\u5e38\u6d41\u884c\u7684JavaScript\u6846\u67b6\uff0c\u5b83\u53ef\u4ee5\u5e2e\u52a9\u5f00\u53d1\u8005\u5feb\u901f\u6784\u5efa\u73b0\u4ee3\u5316\u7684Web\u5e94\u7528\u7a0b\u5e8f\u3002\u5728\u5f00\u53d1Vue\u5e94\u7528\u7a0b\u5e8f\u65f6\uff0c\u6211\u4eec\u901a\u5e38\u4f1a\u4f7f\u7528Webpack\u7b49\u6253\u5305\u5de5\u5177\u6765\u5c06\u4ee3\u7801\u6253\u5305\u6210\u4e00\u4e2a\u6216\u591a\u4e2aJavaScri<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[4282,12,14,2888,16],"topic":[],"class_list":["post-15835","post","type-post","status-publish","format-standard","hentry","category-exekf","tag-dmg","tag-12","tag-14","tag-htmlexe","tag-16"],"_links":{"self":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/posts\/15835","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\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/comments?post=15835"}],"version-history":[{"count":1,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/posts\/15835\/revisions"}],"predecessor-version":[{"id":15848,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/posts\/15835\/revisions\/15848"}],"wp:attachment":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/media?parent=15835"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/categories?post=15835"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/tags?post=15835"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/topic?post=15835"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}