Skip to content

Instantly share code, notes, and snippets.

@zezic

zezic/index.js Secret

Created Aug 3, 2018
Embed
What would you like to do?
Fetching Objects from Bucket
import getBucket from '~/lib/cosmic'
export const state = () => ({
author: null
})
export const mutations = {
setAuthor (state, author) {
state.author = author
}
}
export const actions = {
async nuxtServerInit ({ commit }) {
const bucket = await getBucket()
const response = await bucket.getObjects({
type: 'authors',
limit: 1,
hide_metafields: true
})
if (response.status !== 'empty') {
const author = response.objects[0]
commit('setAuthor', author)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment