vue for循环中使用setTimeout没用 笔记
this.fileList.forEach(file => {
setTimeout(() => {
console.log(new Date().getTime())
this.fileUpload(file)
}, 1000)
})
代码中打印的时间戳并没有延时1s钟,也就是说 setTimeout 这个延时没起作用;
网上找了一些博客,试了都没啥用;请教了一下大牛解决了,这里记录一下
this.fileList.forEach((file, index) => {
setTimeout(() => {
console.log(new Date().getTime())
this.fileUpload(file)
}, 1000 * index)
})
下面博客中有讲为啥不生效的原理,有兴趣的可以看下