-
-
Save zezic/f5fd017df87029ae629978cc29fcf0f4 to your computer and use it in GitHub Desktop.
Fetching Objects from Bucket
This file contains 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
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