vue作为渲染进程使用remote
yarn add @electron/remote --dev
主进程代码
const remote = require("@electron/remote/main");
remote.initialize();
function init_vue_app_login() {
vue_app_login = new BrowserWindow({
webPreferences: {
enableRemoteModule: true,
nodeIntegration: true,
contextIsolation: false,
// 禁用同源策略,允许跨域
webSecurity: false
}
});
vue_app_login.loadURL(
isDev
? "http://localhost:3000"
: `file://${path.join(__dirname, "../dist/index.html")}`
);
remote.enable(vue_app_login.webContents);
}
渲染进程代码
const remote = require("@electron/remote");
function test() {
remote.getCurrentWindow().setSize(1000, 900);
console.log(remote,"remote==========");
}
手写拖动
const remote = require("@electron/remote");
const win = remote.getCurrentWindow();
setup(){
let isDrag = ref(false);
let moveX = ref(0);
let moveY = ref(0);
let winBounds = ref();
const handleHeaderMouseDown = () => {
document.body.addEventListener('mousedown', (e) => {
isDrag = true
moveX = e.screenX
moveY = e.screenY
winBounds = win.getBounds();
})
window.addEventListener('mousemove', (e) => {
if (!isDrag) {
return
}
const { x, y } = winBounds;
let newWinX = x + (e.screenX - moveX)
let newWinY = y + (e.screenY - moveY)
// win.setPosition(Math.min(size.width-346,Math.max(0,x)), Math.min(size.height-78,Math.max(0,y)))
win.setBounds({
x: newWinX,
y: newWinY
})
})
window.addEventListener('mouseup', () => {
isDrag = false
})
}
}