Skip to content

How nuxt server requests #132

Answered by hixb
xiao-ice asked this question in Q&A
Discussion options

You must be logged in to vote

How nuxt server requests

export default { data: () => ({ posts: [] }), async fetch() { this.posts = await this.$http.$get('https://api.nuxtjs.dev/posts') }, fetchOnServer: false, // multiple components can return the samefetchKeyand Nuxt will track them both separately fetchKey: 'site-sidebar', // alternatively, for more control, a function can be passed with access to the component instance // It will be called increatedand must not depend on fetched data fetchKey(getCounter) { // getCounter is a method that can be called to get the next number in a sequence // as part of generating a unique fetchKey. return this.someOtherData + getCounter('sidebar') } }

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by xiao-ice
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants