Last active
June 10, 2020 09:20
-
-
Save maratumba/0a8579ae43e06cda48d606ca23d3f404 to your computer and use it in GitHub Desktop.
Server side data aquisition using nuxt and axios with authorization
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
<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