electron学习----文件拖拽
2019-10-29 本文已影响0人
二营长家的张大炮
image.png
<div class="dropwrap" id="dropwrap">
支持拖拽
</div>
/**
* 渲染进程
*/
const fs = require('fs');
function getProcessInfo() {
console.log("cpu", process.env)
}
const dropwrapper = document.getElementById("dropwrap");
dropwrapper.addEventListener('drop', (e) => {
e.preventDefault()
const files = e.dataTransfer.files;
if (files) {
console.log('path',files[0].path )
const content = fs.readFileSync(files[0].path)
console.log('content',content.toString())
}
})
dropwrapper.addEventListener('dragover', (e) => {
e.preventDefault();
})