Skip to content

Commit

Permalink
Merge pull request #241 from storyblok/fix/add-api-options-to-key
Browse files Browse the repository at this point in the history
fix: add apiOptions to the unique key
  • Loading branch information
Dawntraoz authored Nov 30, 2022
2 parents 545971d + a04841f commit e643cd0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
5 changes: 3 additions & 2 deletions lib/src/runtime/composables/useAsyncStoryblok.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ export const useAsyncStoryblok = async (
apiOptions = {},
bridgeOptions = {}
) => {
const story = useState(url, () => null);
const uniqueKey = `${JSON.stringify(apiOptions)}${url}`;
const story = useState(`${uniqueKey}-state`, () => null);
const storyblokApiInstance = useStoryblokApi();

onMounted(() => {
Expand All @@ -20,7 +21,7 @@ export const useAsyncStoryblok = async (
});

const { data } = await useAsyncData(
url,
`${uniqueKey}-asyncdata`,
async () => await storyblokApiInstance.get(`cdn/stories/${url}`, apiOptions)
);
story.value = data.value.data.story;
Expand Down
6 changes: 5 additions & 1 deletion playground/pages/index.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<script setup>
const story = await useAsyncStoryblok("vue", { version: "draft" });
const story = await useAsyncStoryblok("vue", {
version: "draft",
language: "en",
resolve_relations: ["popular-articles.articles"]
});
const richText = computed(() => renderRichText(story.value.content.richText));
</script>

Expand Down

0 comments on commit e643cd0

Please sign in to comment.