Skip to content

Instantly share code, notes, and snippets.

@DominikAngerer
Created February 15, 2019 16:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DominikAngerer/e350c7cf6a048b0db75768aba5fc26f4 to your computer and use it in GitHub Desktop.
Save DominikAngerer/e350c7cf6a048b0db75768aba5fc26f4 to your computer and use it in GitHub Desktop.
Nuxt _language/index.vue
<template>
<section class="util__container">
<component v-if="story.content.component" :key="story.content._uid" :blok="story.content" :is="story.content.component"></component>
</section>
</template>
<script>
export default {
data () {
return { story: { content: {} } }
},
mounted () {
this.$storyblok.init()
this.$storyblok.on(['change', 'published'], () => {
location.reload(true)
})
},
asyncData (context) {
// Check if we are in the editor mode
let version = context.query._storyblok || context.isDev ? 'draft' : 'published'
// Load the JSON from the API
return context.app.$storyapi.get(`cdn/stories/${context.params.language}/home`, {
version: version,
cv: context.store.state.cacheVersion
}).then((res) => {
return res.data
}).catch((res) => {
context.error({ statusCode: res.response.status, message: res.response.data })
})
}
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment