problem description
this problem is encountered in the nuxtServerInit of the nuxt framework, which is used for server rendering. When this method blocks on the server side and waits for promise to be returned, I want to execute multiple promise, orderly in this method. Because other promise is based on the promise return value of a certain one, the blocking here will not wait for the completion of execution in the then when calling with then (), and the sequential execution cannot be guaranteed with promise.all. Solve
the environmental background of the problems and what methods you have tried
related codes
/ / Please paste the code text below (do not replace the code with pictures)
nuxtServerInit (store, {params, route, req}) {/ / it will only block to return promise
const initData = [
store.dispatch("getToken"),//token
store.dispatch("getLawyerByIndex")//token
]
return Promise.all (initData)
}
chain call can only get "getToken", won"t get" getLawyerByIndex", can be obtained with promise.all, but there is no guarantee for sequential execution