var uploadGallery = Vue.component('uploadGallery', {
<div class="add-image-row">
<h2><small>Add gallery images here</small></h2>
<input type='file' accept='image/*' @change="displaySelected">
<div v-show="imageSelected">
<a href="javascript:void(0);" class="btn btn-success right" value="Add to gallery" @click.prevent="addToGallery">Add to gallery</a>
<a href="javascript:void(0);" class="btn btn-danger left" value="Select another image" @click.prevent="resetSelection">Select another image</a>
<div class="col-md-6" v-show="currentImg != '' ">
<img :src="currentImg" alt="image" width="80%">
<h3>Gallery ({{imgNum}})</h3>
<div v-show=" imgNum > 0 ">
<h3><small>Click on an image to remove it from the gallery</small></h3>
<div class="col-xs-2" v-for="(data, key, index) in imgParsed" :key="index">
<a v-show="data != null" href='javascript:void(0);' @click.prevent="showRemove(key)">
<img :src="data" :alt="key">
<div class="row" v-show="removingImage[key]">
<a href="javascript:void(0);" class="btn btn-danger right" value="Remove image" @click.prevent="remove(key)">Remove this image</a>
<a href="javascript:void(0);" class="btn btn-success left" value="Cancel" @click.prevent="hideRemove(key)">Cancel</a>
displaySelected: function() {
this.imageSelected = true;
let currentImg = event.target.files[0];
this.getImgdata(currentImg);
getImgdata: function(img) {
let reader = new FileReader();
reader.readAsDataURL(img);
reader.onload = event => {
this.currentImg = event.target.result;
addToGallery: function() {
this.removingImage['image' + (this.imgNum + 1)] = false;
this.images.append('image' + (this.imgNum + 1), this.currentImg);
this.imgParsed = this.parseFormData(this.images.entries());
resetSelection: function() {
this.imageSelected = false;
document.getElementById('app').getElementsByTagName('input').item(0).value = null;
showRemove: function(img) {
var a = this.removingImage[img]
this.removingImage = Object.assign({}, this.removingImage, { [img]: true })
var b = this.removingImage[img]
console.log('a = ' + a, 'b = ' + b)
if (a == b && a == false) {
console.log('removingImage not updating')
hideRemove: function(img) {
this.removingImage[img] = false;
delete this.removingImage[img]
delete this.imgParsed[img];
newObj[value[0]] = value[1];
return this.imgParsed == null ? 0 : Object.keys(this.imgParsed).length;
console.log(this.imgParsed)