<script> const { ipcRenderer } = require('electron') ipcRenderer.on('webview-print-render', (event, info) => { // 执行渲染 document.getElementById('bd').innerHTML = info.html ipcRenderer.sendToHost('webview-print-do') }) </script>
这里用到了electron-store存取本地数据
background.js 引入 初始化挂载在global
import ElectronStore from 'electron-store' // ElectronStore 默认数据 import electronDefaultData from './config/electron-default-data' let electronStore app.on('ready', async() => { // 初始化配置文件 electronStore = new ElectronStore({ defaults: electronDefaultData, cwd: app.getPath('userData') }) global.electronStore = electronStore })
src/plugins/inject.js
注册$electronStore
// eslint-disable-next-line import { remote } from 'electron' export default { /* eslint no-param-reassign: "error" */ install(Vue) { Vue.prototype.$electronStore = remote.getGlobal('electronStore') } }
然后你就可以在vue文件里读取了
this.$electronStore.get('printForm') 和 this.$electronStore.set('printForm', val.name)