console
const uploadEl = document.querySelector('.upload')
uploadEl.addEventListener('dragover', (e) => {
e.preventDefault()
e.stopPropagation()
})
uploadEl.addEventListener('drop', (e) => {
e.preventDefault()
e.stopPropagation()
const files = this.files || e.dataTransfer.files
const reader = new FileReader()
reader.readAsText(files[0], 'utf-8')
reader.onload = function (evt) {
var text = evt.target.result
dashboard.innerText = text
}
})
<div class="upload">
拖入文件上传
</div>
<div class="view">
1
</div>
html,body {
margin: 0;
}
body {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
height: 100vh;
}
.upload {
width: 320px;
height: 120px;
background: #ccc;
border-radius: 4px;
display: flex;
justify-content: center;
align-items: center;
color: #fff;
}
.view {
width: 320px;
height: 120px;
margin-top: 10px;
box-sizing: border-box;
border-radius: 4px;
border: 1px solid #ccc;
overflow-y: auto;
padding: 10px;
}