Methods: {
Submit () {
Enclosing uploadImg ()
//waiting for the picture to finish and then perform the following actions
.
},
UploadImg () {
Enclosing imgArray. ForEach (item=& gt; {
DoUpload (item)/upload/execution, it is a network of the asynchronous request
})
}
}
I tried to use the following way to synchronize
Methods: {
Submit () {
Enclosing uploadImg ()
//waiting for the picture to finish and then perform the following actions
.
},
Async uploadImg () {
Await this. ImgArray. ForEach (item=& gt; {
DoUpload (item)/upload/execution, it is a network of the asynchronous request
})
}
}
Methods: {
Async submit () {
Await this. UploadImg ()
//waiting for the picture to finish and then perform the following actions
.
},
UploadImg () {
The return of new Promise ((resolve, reject)=& gt; {
Enclosing imgArray. ForEach (item=& gt; {
DoUpload (item)/upload/execution, it is a network of the asynchronous request
})
The resolve ()
})
}
}
Can achieve synchronization effect, picture upload and other operation is executed asynchronously, excuse me each front-end bosses this need to do
CodePudding user response:
You put other operating upload network request to return the result of implement goodCodePudding user response:
Define a variable to change the value of the variable to monitor the variable do after upload other actionsCodePudding user response:
Methods: {
Async submit () {
Await this. UploadImg ()
//waiting for the picture to finish and then perform the following actions
.
},
UploadImg () {
Const arr=[]
Enclosing imgArray. ForEach (async (item)=& gt; {
Arr. Push (doUpload (item))/upload/execution, it is a network of the asynchronous request
})
Return Promise. All (arr)
}
}
//try this
CodePudding user response:
Line 10 no async