electron-vue打开⽂件⽬录,打开⽂件夹,1.打开⽗⼦模态创建,
<button @click="showModalHandler">⽗⼦模态窗⼝</button>
//renderer渲染器中主注册事件
showModalHandler() {
ipcRenderer.send("child-down-modal");
}
//主进程中触发事件
/**
* ⽗⼦模态窗⼝
*/
let childDownModal;
<('child-down-modal', () => {
childDownModal = new BrowserWindow({
parent: mainWindow,
modal: true,
show: false,
width: 300,
height: 300,
resizable: false,
backgroundColor: "#fff",
frame: false,
hasShadow: true,
closable: true,
webPreferences: {
devTools: false
}
})
<('ready-to-show', () => {
childDownModal.show();
})
childDownModal.loadURL(winURL + '#/downloadModal')
})
//关闭模态窗⼝
<('close-down-modal', () => {
childDownModal.hide();
})
View Code
2、打开⽂件⽬录
const {shell}  = require('electron').remote //渲染器中
shell模块提供与桌⾯集成相关的功能。
<template>
<div class="download-container sureDrag">
<button @click="openFileHandler">打开⽂件⽬录</button>
</div>
</template>
<script>
const ipcRenderer = require("electron").ipcRenderer;
export default {
methods: {
electron vue教程openFileHandler() {
const { shell } = require("electron").remote;
shell.showItemInFolder("D:CloudMusic");
}
}
};
</script>
3.对话框打开⽂件
const {dialog} = require('electron').remote;
dialog.showOpenDialog()//可默认打开⽂件