electron实现静默打印的示例代码实现静默打印的示例代码
主要介绍了electron实现静默打印的示例代码,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有
一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
前言前言
electron+vuecli3 实现设置打印机,静默打印小票功能
网上相关的资料比较少,这里给大家分享一下,希望大家可以少踩一些坑
github地址
必须要强调一下的是electron的版本必须是3.0.0不能,我尝试了4和5都没有实现
效果图效果图
使用使用
git clone https://github.com/sunnie1992/electron-vue-print-demo.git
npm install
npm run electron:serve
实现实现
操作思路
1.用户点击打印
2.查询本地electron-store(用来向本地存储,读取数据)是否存打印机名称
3.已经设置,直接打印
4.没有设置,弹出设置打印机框
5.用户设置好确认后打印
首页App.vue引入了两个组件,一个是主动设置打印机的弹出printDialog
另外一个是打印组件,打印是通过webview将需要打印的内容渲染到html页面然后就能打印了
<template>
<div id="app">
<el-button type="primary" @click="showPrint">设置打印机</el-button>
<printDialog :dialog-visible="dialogVisible" @cancel="handlePrintDialogCancel" />
<pinter ref="print" :html-data="HtmlData"></pinter>
<el-table :data="tableData" style="width: 100%">
<el-table-column prop="date" label="日期" width="180" column-key="date">
</el-table-column>
<el-table-column prop="name" label="姓名" width="180">
</el-table-column>
<el-table-column prop="address" label="地址">
</el-table-column>
<el-table-column label="操作">
<template slot-scope="scope">
<el-button type="primary" @click="doPrint(scope.row)">打印</el-button>
</template>
</el-table-column>
</el-table>
</div>
</template>
<script>
import { ipcRenderer } from 'electron'
import printDialog from './components/PrintDialog.vue'
import Pinter from './components/pinter.vue'
export default {
name: 'App',
components: {
Pinter,
printDialog
},
data() {
return {
dialogVisible: false,
HtmlData: '',
printList: [],
tableData: [{
date: '2016-05-02',
评论0