道具对象不适用于已安装的方法
Props object not working on mounted method
我有 preFile 变量 whitch 来自道具,我正在改变安装方法但是当我尝试使用 preFile 传递fileProcess 方法,因为它不起作用,但如果我从另一个方法调用 fileProcess 一切正常。当我调用 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)
}
},
不同的方法(我通过点击调用这个方法):
asd(){
console.log(this.preFile)
if (this.gallery){
this.fileProcess(this.preFile)
}else{
this.gallery = true
this.fileProcess(this.preFile)
}
},
和 fileProcess 方法:
fileProcess(files){
for (let key in files){
}
},
我找到了解决方案。问题可能是异步操作。 @aside 如此处所述 但我使用不同的方法。
我为此使用了 settimeout :
setTimeout(function() {
if (this.gallery){
this.fileProcess(this.images)
}else{
this.gallery = true
this.fileProcess(this.images)
}
}.bind(this), 1000);
我有 preFile 变量 whitch 来自道具,我正在改变安装方法但是当我尝试使用 preFile 传递fileProcess 方法,因为它不起作用,但如果我从另一个方法调用 fileProcess 一切正常。当我调用 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)
}
},
不同的方法(我通过点击调用这个方法):
asd(){
console.log(this.preFile)
if (this.gallery){
this.fileProcess(this.preFile)
}else{
this.gallery = true
this.fileProcess(this.preFile)
}
},
和 fileProcess 方法:
fileProcess(files){
for (let key in files){
}
},
我找到了解决方案。问题可能是异步操作。 @aside 如此处所述
我为此使用了 settimeout :
setTimeout(function() {
if (this.gallery){
this.fileProcess(this.images)
}else{
this.gallery = true
this.fileProcess(this.images)
}
}.bind(this), 1000);