[Vuejs]-How to stop vuejs method variable from updating data variables

1👍

More simple solution would be

var images=JSON.parse(JSON.stringify(this.person.images))

avoid looping.

1👍

Because in Javascript when you do :

 var images = this.person.images;

The value of images is now a reference for “this.person.images”.

One idea to solve that problem is to loop through each item of “Images” Array and add it to the “att” array like so :

addImage (file) {
    var URL = 'http://foo.com/api'; 

    var images = this.person.images;

    let att = []
    if(images.length) {

   for (var i = 0,len = images.length; i < len; i++) {
        att.push(images[i]);
    }
        att.push(file.name)
    }else{
        att.push(file.name)
    }

    axios.post(URL, {
        attachements: att
    }).then(

        // update dom

    ).catch(err => {})
},

Basically replace att = images with :

   for (var i = 0,len = images.length; i < len; i++) {
            att.push(images[i]);
        }
👤Tarek

Leave a comment