I
I
Ismail942020-12-10 23:17:21
Vue.js
Ismail94, 2020-12-10 23:17:21

How to remove an element from a Vue object?

I am uploading files to the server with a preview.

imgPreview: [],
            form: new Form({
                 images: []
            })

//При выборе картинок вызывается метод
uploadImg(img){
                this.form.images = img.target.files;

                for(let image of this.form.images){
                    let reader = new FileReader();
                    reader.readAsDataURL(image);
                    reader.onloadend = (image) => {
                        this.imgPreview.push(reader.result);
                    }
},


There is also a method to remove the image from the preview
<button type="button" slot="button" @click="deleteImgInArray(index)">удалить</button>
deleteImgInArray(index){
            this.$delete(this.form.images,index); //Так не удаляется
            this.$delete(this.imgPreview,index);
        },

When you click on the delete button, the image is removed from the imgPreview array, how to remove it from the images array as well. In the console I will display the images property
console.log(this.form.images);
FileList {0: File, 1: File, 2: File, 3: File, length: 4}length: 40: File1: File2: File3: File__proto__: FileList

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Belyaev, 2020-12-11
@bingo347

https://developer.mozilla.org/en/docs/Web/JavaScript...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question