在使用vue或者nuxt中,我们需要使用axios去发送多个http请求,参考了axios的官方说明你也许会想到使用axios.all发送请求,但是这样可能会出现一些异常错误:
(node:9360) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 2): TypeError: __WEBPACK_IMPORTED_MODULE_2__plugins_axios__.a.all is not a function
所以正确的使用姿势是采用Promise.all
来发送多个请求. 具体实现请参考如下实现:
Heap Stack Blog(pingbook.top)Nuxt How to send multiple requests in asyncData