Error message
Some checks failed
Cat or Not - frontend/inzynieria_frontend/pipeline/head There was a failure building this commit

This commit is contained in:
Novembert 2021-12-19 19:08:14 +01:00
parent 312b6e7b80
commit 02589af438

View File

@ -40,6 +40,9 @@
@change="onFileChange" @change="onFileChange"
> >
</div> </div>
<p v-if="showError">
Akceptowane rozszerzenia to: jpg, jpeg, png
</p>
</div> </div>
</div> </div>
</template> </template>
@ -65,7 +68,8 @@ export default {
url: null, url: null,
size: null, size: null,
file: null, file: null,
name: null name: null,
showError: false
} }
}, },
watch: { watch: {
@ -96,15 +100,23 @@ export default {
document.getElementById(this.id).click() document.getElementById(this.id).click()
}, },
getFileInfo (file) { getFileInfo (file) {
try { const acceptedExtensions = ['jpg', 'jpeg', 'png']
this.url = URL.createObjectURL(file) const name = file.name
this.name = file.name let extension = name.split('.')[name.split('.').length - 1]
this.file = file extension = extension.toLowerCase()
this.$emit('set', { file: this.file, url: this.url }) if (acceptedExtensions.includes(extension)) {
} catch (e) { try {
this.url = null this.url = URL.createObjectURL(file)
this.name = null this.name = file.name
this.file = null this.file = file
this.$emit('set', { file: this.file, url: this.url })
} catch (e) {
this.url = null
this.name = null
this.file = null
}
} else {
this.showError = true
} }
} }
} }