Home > OS >  Props object not working on mounted method
Props object not working on mounted method

Time:05-09

i have preFile variable whitch is coming from props and i am changing on mounted method but when i try to use preFile to pass fileProcess method, for is not not working but if i call fileProcess from enother method everyting working fine. I cannot find what is problem why my method is not working when i call on mounted

enter image description here

on mounted :

 mounted() {
    
    let file = []
    let index = 0
    Object.entries(this.preData).forEach(entry => {
        let FileURL = this.asset   '/'   this.id   '/'   entry[1]['name']
        this.GetFileObjectFromURL(FileURL, function (fileObject) {
            file[index] = fileObject
            index  
        }, entry[1]['name'])
    });
    this.preFile = file
    console.log(this.preFile)
    if (this.gallery){
        this.fileProcess(this.preFile)
    }else{
        this.gallery = true
        this.fileProcess(this.preFile)
    }
},

diffetrent method (i am calling this method with click):

 asd(){
        console.log(this.preFile)
        if (this.gallery){
            this.fileProcess(this.preFile)
        }else{
            this.gallery = true
            this.fileProcess(this.preFile)
        }
    },

and fileProcess method:

fileProcess(files){
        for (let key in files){
            
        }
    },

CodePudding user response:

i found solition. The promlem is probably asynchronous operations. @aside as mentioned here https://stackoverflow.com/a/58610995/4201269 but i use different method.

i used settimeout for it :

 setTimeout(function() {
    if (this.gallery){
        this.fileProcess(this.images)
    }else{
        this.gallery = true
        this.fileProcess(this.images)
    }
}.bind(this), 1000);
  • Related