有人可以指导我如何使用Storyblok-nuxt发送多个.get()请求吗?
我正在尝试做这样的事情:
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);
}));
谢谢。
答案 0 :(得分:0)
由于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.
})
这里也是有关此内容的完整教程:https://www.storyblok.com/tp/how-to-send-multiple-requests-using-axios