【发布时间】:2020-06-22 14:59:35
【问题描述】:
我在我的 Vue JS Web 应用程序上设置了一个拖放框。该元素是一个简单的 div,当文件被拖放到文件上时,它会处理文件。
我使用https://www.raymondcamden.com/2019/08/08/drag-and-drop-file-upload-in-vuejs 作为指导。
HTML:
<div v-if="status == 'upload'">
<h3> Please fill the data sheet and upload it here!</h3>
<div class="downbox" @drop.prevent="addFile" @dragover.prevent>
<span style="font-size: 60px"><font-awesome-icon icon='cloud-upload-alt'/></span>
<br>
Click to Browse
<br>
or Drag and Drop a File Here
</div>
</div>
JS:
addFile: function(e){
let droppedFiles = e.dataTransfer.files;
if ((droppedFiles[0].name).slice(-5) !== '.xlsx') {
this.$swal({
text: "Please upload a file of type .xlsx",
title: "Incorrect File Type!",
icon: "error",
})
this.status = 'upload'
}
else {
this.file = droppedFiles
this.status = 'show'
}
},
removeFile: function(){
this.file = null
this.status = 'upload'
}
CSS:
.downbox {
width: 500px;
border-radius: 50px;
border-width: 6px;
border-color: white;
border-style: dashed;
background-color: #7a2ab3;
padding: 10px;
font-size: 25px;
font-weight: bold;
transition: 0.6s;
margin-left: auto;
margin-right: auto;
}
.downbox:hover{
background-color: #c56bc5;
}
如您所见,当您将鼠标悬停在 div 上时,背景颜色会发生变化。
但是,当我将文件拖到 div 上时,这种颜色变化不会出现。所以我不知道如果你点击拖动文件,它是否算作“:悬停”。
无论哪种方式,我都想知道我可以在代码中添加什么,以便在我将文件拖到 div 上时更改 CSS 背景颜色属性。
【问题讨论】:
标签: javascript html css vue.js events