Skip to content

Instantly share code, notes, and snippets.

@maratumba
Last active June 10, 2020 09:20
Show Gist options
  • Save maratumba/0a8579ae43e06cda48d606ca23d3f404 to your computer and use it in GitHub Desktop.
Save maratumba/0a8579ae43e06cda48d606ca23d3f404 to your computer and use it in GitHub Desktop.
Server side data aquisition using nuxt and axios with authorization
<template>
<div>
<div v-for="item in items" :key="item.id">
{{ item.name }}
</div>
</div>
</template>
<script>
export default {
data: ()=>({
items: []
}),
asyncData({$axios, route}){ // you have access to $axios instance if you are using nuxt axios module
return $axios.get(`/api/v2/cavemaps/`, {params: route.query}).then( (resp) => { // use query params if you need
// console.log(resp) // inspect response if you need
if(resp.status==200){
return {items: resp.data.results}
}
})
}
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment