-
-
Save t-okushima/2199291ea4c70f60a57dd83d73c738e7 to your computer and use it in GitHub Desktop.
[vue.js] fileアップロード用のdrag&dropエリアを持つコンポーネントを作成する
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<div | |
class="drag-area" | |
@dragover.prevent | |
@drop.prevent="upload" | |
> | |
<input type="file" @change="upload" /> | |
<span>{{ areaMessage }}</span> | |
</div> | |
</template> | |
<script> | |
export default { | |
name: "Upload", | |
props: { | |
areaMessage: { | |
type: String, | |
default: "Upload File" | |
} | |
}, | |
methods: { | |
upload(event) { | |
const files = event.target.files || event.dataTransfer.files; | |
this.$emit("upload", files); | |
} | |
} | |
}; | |
</script> | |
<style lang="sass" scoped> | |
.drag-area | |
width: 100% | |
min-width: 200px | |
height: 100% | |
min-height: 200px | |
border: 1px dotted rgba(0,0,0,0.1) | |
border-radius: 8px | |
display: flex | |
justify-content: center | |
align-items: center | |
flex-direction: column | |
background-color: #F5F5F5 | |
input | |
opacity: 0 | |
</style> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment