Although this question has been raised before, I am struggling with implementing the code in vuejs. Despite my efforts, I have not been able to achieve any results yet. I have included my code below. Could someone please assist me? Here is my code. Thanks
html
<template>
<div class="fileUpload">
<b-container fluid>
<h4>Image Overview</h4>
<b-button @click="$refs.fileInput.click()" class="btn-right">Select an image</b-button>
<b-table @row-clicked="viewImage" striped hover :items="images" :fields="image_fields"></b-table>
<input style="display: none" ref="fileInput" type="file" @change="fileSelected" enctype="multipart/form-data">
<b-button variant="success" class="btn-right" @click="uploadImage" method="post">Upload image</b-button>
</b-container>
</div>
js
<script>
export default {
name: 'listImage',
data() {
return {
selectedFile: null,
images: [],
image_fields: ['id', 'name'],
total_images: 1
}
},
methods: {
fileSelected(evt) {
evt.preventDefault()
console.log(evt);
this.selectedFile = evt.target.files[0]
},
uploadImage() {
var data = new FormData();
data.append('image', this.selectedFile, this.selectedFile.data)
var token = sessionStorage.getItem('token')
const config = {
headers: {
'Content-Type': 'multipart/form-data'
}
}
window.API.post('https://110.10.56.10:8000/images/?token=' + token, data, config)
.then(response => this.$router.push('/listImage'))
.catch((error) => {
console.log(JSON.stringify(error))
})
}
}
}