# electron-print **Repository Path**: vectorlin/electron-print ## Basic Information - **Project Name**: electron-print - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2019-11-08 - **Last Updated**: 2020-12-18 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README 简书上写了更详细的的文档 https://www.jianshu.com/p/45df1dc37478 项目环境 node 10.15.3 yarn 1.15.2 win10 代码完成时间2019-4-18 废话不多说,先放源码 GitHub [https://github.com/951477037/electron-print](https://github.com/951477037/electron-print) ``` git clone https://github.com/951477037/electron-print.git ``` ``` //安装依赖 yarn ``` ``` //运行项目 yarn run dev ``` ``` //打包项目 yarn run build ``` 目录结构  先在主进程 /src/main/index.js ``` //引入ipcMain import { app, BrowserWindow, ipcMain } from 'electron' ```  在createWindow方法里添加以下代码,获取打印机列表 ``` //在主线程下,通过ipcMain对象监听渲染线程传过来的getPrinterList事件 ipcMain.on('getPrinterList', (event) => { //在主线程中获取打印机列表 const list = mainWindow.webContents.getPrinters(); //通过webContents发送事件到渲染线程,同时将打印机列表也传过去 mainWindow.webContents.send('getPrinterList', list); }); ```  接下来在LandingPage.vue中也就是渲染进程中添加一下代码 ``` const ipcRenderer = require("electron").ipcRenderer; ``` ``` //使用ipcRenderer与主进程通信,并获取返回值 ipcRenderer.send("getPrinterList"); //监听主线程获取到打印机列表后的回调 ipcRenderer.once("getPrinterList", (event, data) => { //data就是打印机列表 console.log(data); }); ```  输出结果如下  重点来了!!! 在static中新建一个print.html文件(如果你害怕打包后会找不到的话,我在最后会提供一个方法不知道你看得仔不仔细),如下图所示  如果不在static中新建的话会报错(具体原因我明没有深入去研究)  ```