-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
01864d0
commit 89f12d4
Showing
4 changed files
with
119 additions
and
77 deletions.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
<template> | ||
<div> | ||
<div class="imagePreviewWrapper" :style="{ 'background-image': `url(${previewImage})` }" @click="selectImage"> | ||
</div> | ||
|
||
<div class="file-field input-field"> | ||
<div class="btn btn-file"> | ||
<i class="material-icons">attach_file</i> | ||
<span>Загрузить фото</span> | ||
<input type="file" ref="fileInput" @input="pickFile" /> | ||
</div> | ||
<div class="file-path-wrapper"> | ||
<input class="file-path validate" type="text"> | ||
</div> | ||
</div> | ||
</div> | ||
</template> | ||
|
||
|
||
<script> | ||
export default { | ||
name: "img-loader", | ||
data() { | ||
return { | ||
previewImage: null | ||
}; | ||
}, | ||
methods: { | ||
selectImage() { | ||
this.$refs.fileInput.click() | ||
}, | ||
pickFile() { | ||
let input = this.$refs.fileInput | ||
let file = input.files | ||
if (file && file[0]) { | ||
let reader = new FileReader | ||
reader.onload = e => { | ||
this.previewImage = e.target.result | ||
} | ||
reader.readAsDataURL(file[0]) | ||
this.$emit('input', file[0]) | ||
} | ||
} | ||
} | ||
} | ||
</script> | ||
|
||
|
||
<style lang="scss" scoped> | ||
.imagePreviewWrapper { | ||
min-width: 250px; | ||
min-height: 250px; | ||
display: block; | ||
cursor: pointer; | ||
margin: 15px auto 30px; | ||
background-size: contain; | ||
background-repeat: no-repeat; | ||
background-position: center center; | ||
} | ||
.btn { | ||
&-file { | ||
display: flex; | ||
justify-content: space-between; | ||
font-size: 11px; | ||
line-height: 3rem; | ||
font-weight: 600; | ||
vertical-align: middle; | ||
padding-left: 5px; | ||
padding-right: 10px; | ||
i { | ||
margin-right: 4px; | ||
} | ||
} | ||
.file-field .btn { | ||
height: 3rem; | ||
} | ||
} | ||
</style> |