asyncData()
Estimated reading time: 1 minuteasyncData()
asyncData is a function
. it is called everytime before loading page.it will be called server-side
and client-side
.
export default {
data () {
return { project: 'default' }
},
asyncData (context) {
return { project: 'nuxt' }
}
}
export default {
async asyncData ({ params }) {
let { data } = await axios.get(`https://my-api/posts/${params.id}`)
return { title: data.title }
}
}
you can't access data with this keyword inside asyncData
.
~ resource
fetch
fetch
is function
and same as asyncData. fetch can’t accept component data
.
function
✘ component data ✘
layout
string
,function