@storyblok/nuxt 5.0.2 → 5.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
declare
|
|
1
|
+
import type { ISbStoriesParams, StoryblokBridgeConfigV2 } from '@storyblok/vue';
|
|
2
|
+
export declare const useAsyncStoryblok: (url: string, apiOptions?: ISbStoriesParams, bridgeOptions?: StoryblokBridgeConfigV2) => Promise<any>;
|
|
@@ -1,28 +1,18 @@
|
|
|
1
1
|
import { useStoryblokApi, useStoryblokBridge } from "@storyblok/vue";
|
|
2
|
-
import { useAsyncData, useState, onMounted } from "#imports";
|
|
3
|
-
|
|
4
|
-
const useAsyncStoryblok = async (url, apiOptions = {}, bridgeOptions = {}) => {
|
|
2
|
+
import { useAsyncData, useState, onMounted, createError } from "#imports";
|
|
3
|
+
export const useAsyncStoryblok = async (url, apiOptions = {}, bridgeOptions = {}) => {
|
|
5
4
|
const uniqueKey = `${JSON.stringify(apiOptions)}${url}`;
|
|
6
|
-
const story = useState(`${uniqueKey}-state`, () =>
|
|
5
|
+
const story = useState(`${uniqueKey}-state`, () => ({}));
|
|
7
6
|
const storyblokApiInstance = useStoryblokApi();
|
|
8
|
-
|
|
9
7
|
onMounted(() => {
|
|
10
8
|
if (story.value && story.value.id) {
|
|
11
|
-
useStoryblokBridge(
|
|
12
|
-
story.value.id,
|
|
13
|
-
(evStory) => (story.value = evStory),
|
|
14
|
-
bridgeOptions
|
|
15
|
-
);
|
|
9
|
+
useStoryblokBridge(story.value.id, (evStory) => story.value = evStory, bridgeOptions);
|
|
16
10
|
}
|
|
17
11
|
});
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
story.value = data.value.data.story;
|
|
24
|
-
|
|
12
|
+
const { data, error } = await useAsyncData(`${uniqueKey}-asyncdata`, () => storyblokApiInstance.get(`cdn/stories/${url}`, apiOptions));
|
|
13
|
+
if (error.value?.response.status >= 400 && error.value?.response.status < 600) {
|
|
14
|
+
throw createError({ statusCode: error.value?.response.status, statusMessage: error.value?.message.message });
|
|
15
|
+
}
|
|
16
|
+
story.value = data.value?.data.story;
|
|
25
17
|
return story;
|
|
26
18
|
};
|
|
27
|
-
|
|
28
|
-
export default useAsyncStoryblok;
|