Created
February 15, 2019 16:18
-
-
Save DominikAngerer/e350c7cf6a048b0db75768aba5fc26f4 to your computer and use it in GitHub Desktop.
Nuxt _language/index.vue
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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