网站首页 > 博客文章 正文
最近做了Electron-vue相关的客户端开发
做出了如下总结:
利用new BrowserWindow()方法创建窗口对象
能满足开发项目的窗口属性有
win = new BrowserWindow({
width: 700,
height: 600,
minWidth:1000,
minHeight:600,
// 文档https://www.w3cschool.cn/electronmanual/electronmanual-browser-window.html
webPreferences: {
nodeIntegration: true,
webviewTag: true,
webSecurity: false,
allowDisplayingInsecureContent: true,
allowRunningInsecureContent: true,
},
})
如果想把客户端窗口顶部菜单去掉
在webPreferences同级节点加上
frame: false,// 去除顶部操作按钮
自定义最小化、最大化、关闭窗口按钮功能实现:
在主进程中写入以下代码段
// 控制窗口大小以及关闭
ipcMain.on('close', () => {
win.destroy();
})
// 窗口最小化
ipcMain.on('toMinimize', () => {
win.minimize();
})
// 窗口最大化和还原
ipcMain.on('toMaximize', () => {
if (win.isMaximized()) {
win.unmaximize();
} else {
win.maximize();
}
})
如果想拖拽窗口利用如下方法:
首先在vue的main.js中引入electron的ipcRenderer
Vue.prototype.$electron = window.require('electron').ipcRenderer
设置公用vue组件为窗口顶部,id为web-top
在mounted中写入
let _this = this;
dragElement(document.getElementById(("web-top")));
function dragElement(elmnt) {
let [pos1,pos2,pos3,pos4] = [0,0,0,0];
if (document.getElementById(elmnt.id + "header")) {
document.getElementById(elmnt.id + "header").onmousedown = dragMouseDown;
} else {
elmnt.onmousedown = dragMouseDown;
}
function dragMouseDown(e) {
e = e || window.event;
pos3 = e.clientX;
pos4 = e.clientY;
document.onmouseup = closeDragElement;
document.onmousemove = elementDrag;
}
function elementDrag(e) {
e = e || window.event;
// e.movementX、e.movementY分别为窗口移动的方位和像素,为正负数值
var param = e.movementX + "," + e.movementY;
_this.$electron.send('changeWinPosition',param);
}
function closeDragElement() {
document.onmouseup = null;
document.onmousemove = null;
}
}
在主进程中写入
// 拖拽调整窗口位置
ipcMain.on('changeWinPosition', (event, arg) => {
let [x,y] =[0,0];
x = arg.split(",")[0];
y = arg.split(",")[1];
win.setBounds({ x: win.getPosition()[0] + parseInt(x), y: win.getPosition()[1] + parseInt(y) })
})
猜你喜欢
- 2024-10-21 IntersectionObserver: 教你如何实现一个Vue无限滚动的组件
- 2024-10-21 支持服务器端渲染的移动端Vue组件——NutUI
- 2024-10-21 循序渐进Vue+Element 前端应用开发(6)—常规Element界面组件使用
- 2024-10-21 vue动态路由(支持嵌套路由)和动态菜单UI开发框架,无偿源码
- 2024-10-21 1小时搞定卡片拖拽、自动排列交换位置、拖拽数据存取
- 2024-10-21 如何使用 vue + intro 实现后台管理系统的新手引导
- 2024-10-21 零基础入门vue开发(vue开发步骤)
- 2024-10-21 前端路由与vue-router的基本用法(前端路由实现的两种方式)
- 2024-10-21 史上最全 vue-router 讲解 !!!(vue,router)
- 2024-10-21 2021,排名前 15 的 Vue 后台管理模板
你 发表评论:
欢迎- 367℃用AI Agent治理微服务的复杂性问题|QCon
- 358℃初次使用IntelliJ IDEA新建Maven项目
- 356℃手把手教程「JavaWeb」优雅的SpringMvc+Mybatis整合之路
- 351℃Maven技术方案最全手册(mavena)
- 348℃安利Touch Bar 专属应用,让闲置的Touch Bar活跃起来!
- 346℃InfoQ 2024 年趋势报告:架构篇(infoq+2024+年趋势报告:架构篇分析)
- 345℃IntelliJ IDEA 2018版本和2022版本创建 Maven 项目对比
- 342℃从头搭建 IntelliJ IDEA 环境(intellij idea建包)
- 最近发表
- 标签列表
-
- powershellfor (55)
- messagesource (56)
- aspose.pdf破解版 (56)
- promise.race (63)
- 2019cad序列号和密钥激活码 (62)
- window.performance (66)
- qt删除文件夹 (72)
- mysqlcaching_sha2_password (64)
- ubuntu升级gcc (58)
- nacos启动失败 (64)
- ssh-add (70)
- jwt漏洞 (58)
- macos14下载 (58)
- yarnnode (62)
- abstractqueuedsynchronizer (64)
- source~/.bashrc没有那个文件或目录 (65)
- springboot整合activiti工作流 (70)
- jmeter插件下载 (61)
- 抓包分析 (60)
- idea创建mavenweb项目 (65)
- vue回到顶部 (57)
- qcombobox样式表 (68)
- vue数组concat (56)
- tomcatundertow (58)
- pastemac (61)
本文暂时没有评论,来添加一个吧(●'◡'●)