一、运行项目报错:process is not defined
下方是我微信公众号的二维码,可以扫码关注以下,后期博文推送主要在公众号上面,有什么问题也可以通过公众号跟我发消息哦~
解决方法:
在 .electron-vue —> webpack.renderer.config.js 里加入如下代码:
templateParameters(compilation, assets, options) {
return {
compilation: compilation,
webpack: compilation.getStats().toJson(),
webpackConfig: compilation.options,
htmlWebpackPlugin: {
files: assets,
options: options
},
process,
};
},
二、
当主窗口未设置resizable:false; 自定义的窗口最大化及还原功能正常,但是 当设置了 resizable: false 时,自定义窗口最大化之后还原问题:
解决方法:
1、在主进程 main —> index.js里
function createWindow() {
mainWindow = new BrowserWindow({
width: 1366,
height: 768,
resizable: false, // 可否缩放
webPreferences: { webSecurity: false //允许跨域},
//...
})
//...
}
//...
ipcMain.on('max', (event, arg) => {
if (arg.isFlag) {
mainWindow.maximize()
} else {
mainWindow.setContentSize(1366, 768)
mainWindow.center()
}
})
2、在渲染进程:
<template>
<div>
<div @click="min()">
<img src="@/assets/mini.png" />
</div>
<div @click="max()">
<img v-if="!isFlag" src="@/assets/max.png" />
<img v-else src="@/assets/reset.png" />
</div>
<div @click="close()">
<img src="@/assets/close.png" />
</div>
</div>
</template>
<script>
import { ipcRenderer} from 'electron';
export default {
data () {
return {
isFlag: false, // isFlag为true时,表示最大化
}
},
methods: {
max() {
this.isFlag= !this.isFlag;
ipcRenderer.send("max", { isFlag: this.isFlag});
},
min() {
ipcRenderer.send("min");
},
}
}
</script>