Skip to content

Instantly share code, notes, and snippets.

@zezic

zezic/index.js Secret

Created August 3, 2018 17:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zezic/f5fd017df87029ae629978cc29fcf0f4 to your computer and use it in GitHub Desktop.
Save zezic/f5fd017df87029ae629978cc29fcf0f4 to your computer and use it in GitHub Desktop.
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