简体   繁体   English

使用 Storyblok-nuxt 发送 multiple.get() 请求

[英]Sending multiple .get() requests with Storyblok-nuxt

Can someone please guide me regarding sending multiple.get() requests with Storyblok-nuxt?有人可以指导我使用 Storyblok-nuxt 发送 multiple.get() 请求吗?

I'm trying to do something like this:我正在尝试做这样的事情:

context.app.$storyapi.all([requestOne, requestTwo]).then(
  context.app.$storyapi.spread((...responses) => {
  const responseOne = responses[0];
  const responseTwo = responses[1];

  console.log(responseOne, responseTwo, responesThree);
}));

Thanks.谢谢。

Since the JS client of Storyblok is using an axios wrapper you can do it like this:由于 Storyblok 的 JS 客户端使用的是axios包装器,因此您可以这样做:

import axios from 'axios';

const requestOne = context.app.$storyapi.get('cdn/stories' + 'health', { version: "published" })
const requestTwo = context.app.$storyapi.get('cdn/datasources', { version: "published" })
const requestThree = context.app.$storyapi.get('cdn/stories' + 'vue', { version: "published" })

axios.all([requestOne, requestTwo, requestThree]).then(axios.spread((...responses) => {
  const responseOne = responses[0]
  const responseTwo = responses[1]
  const responesThree = responses[2]
  // use/access the results 
})).catch(errors => {
  // react on errors.
})

Here is also a full tutorial on this: https://www.storyblok.com/tp/how-to-send-multiple-requests-using-axios这里还有一个完整的教程: https://www.storyblok.com/tp/how-to-send-multiple-requests-using-axios

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM