saberland/saber
Do you want to work on this issue?
You can request for a bounty in order to promote it!
Nuxt-like asyncData #511
egoist posted onGitHub
<!-- Please don't delete this template or we'll close your issue -->
<!-- Before creating an issue please make sure you are using the latest version of Saber. -->
Feature request
<!-- Please ask questions via following several ways. -->
<!-- https://chat.saber.land/ -->
<!-- https://stackoverflow.com/questions/ask?tags=saberjs -->
What problem does this feature solve?
Provide an alternative to Gatsby's page query and Nuxt's asyncData.
What does the proposed API look like?
export default {
async getInitialData({ getServerCache }) {
// On server-side, you can access Saber's Node API
if (process.server) {
const reposCount = await axios.get(`https://my.repos.count/api`)
// Return the data you want to inject as component data
// We cache the result as JSON so that you can access it via `getServerCache`
return { reposCount }
}
// On client-side, you use the server cache which is `{ reposCount }`
return getServerCache()
}
}