'Props object not working on mounted method
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
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){
}
},
Solution 1:[1]
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);
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Talha Can |