vue设置前的Vuejs反应性检查



你好,我有一个函数,它接收文件下载的百分比,我使用vue集将属性添加到对象中,因为它还没有响应,现在这个函数每秒都会被调用来更新百分比,我想知道是否可以始终使用vue集中设置它和更新值,或者在我使用vue集之后,检查属性是否在那里,然后定期更新

所以我总是可以这样称呼这个

SettaPerc(fileIndex = -1, profIndex = -1,perc = 0) {
if (profIndex === -1) {
this.$set(this.file[fileIndex], "perc", perc);
} else {
this.$set(this.file[profIndex].linkondi[fileIndex], "perc", perc);
}
},

或者最好做这个

SettaPerc(fileIndex = -1, profIndex = -1, perc = 0) {
if (profIndex === -1) {
if (this.file[fileIndex].perc === undefined) {
this.$set(this.file[fileIndex], "perc", perc);
} else {
this.file[fileIndex].perc = perc
}
} else {
if (this.file[profIndex].linkondi[fileIndex] === undefined) {
this.$set(this.file[profIndex].linkondi[fileIndex], "perc", perc);
} else {
this.file[profIndex].linkondi[fileIndex] = perc
}
}
},

使用它没有真正的缺点$设置,一切都很好。

我的建议是

SettaPerc(fileIndex = -1, profIndex = -1,perc = 0) {
if (profIndex === -1) 
return this.$set(this.file[fileIndex], "perc", perc); 
return this.$set(this.file[profIndex].linkondi[fileIndex], "perc", perc);           
},

所以你可以摆脱额外的其他块

最新更新