Skip to content
Permalink
Browse files

axios and asyncData

  • Loading branch information...
jeffreybiles committed Oct 13, 2019
1 parent b988598 commit a5f810971027063c419c510a94bbdbee81ad85f0
Showing with 10 additions and 27 deletions.
  1. +1 −0 nuxt.config.js
  2. +4 −16 pages/videos/_id.vue
  3. +5 −11 pages/videos/index.vue
@@ -49,6 +49,7 @@ export default {
** See https://axios.nuxtjs.org/options
*/
axios: {
baseURL: 'http://localhost:3000/api'
},
/*
** Build configuration
@@ -6,23 +6,11 @@

<script>
export default {
data() {
async asyncData({$axios, params}) {
let response = await $axios.get(`/videos/${params.id}`)
let video = response.data.data.attributes;
return {
videos: [{
id: '16',
name: 'Intro to NuxtJS'
}, {
id: '1',
name: 'Intro to VueJS'
}, {
id: '71',
name: 'Advanced Techniques for Library X'
}]
}
},
computed: {
video() {
return this.videos.find(v => v.id == this.$route.params.id)
video
}
}
}
@@ -10,18 +10,12 @@

<script>
export default {
data() {
async asyncData({$axios}) {
let response = await $axios.get('/videos')
let videos = response.data.data.map(v => v.attributes);
return {
videos: [{
id: '16',
name: 'Intro to NuxtJS'
}, {
id: '1',
name: 'Intro to VueJS'
}, {
id: '71',
name: 'Advanced Techniques for Library X'
}]
videos
}
},
}

0 comments on commit a5f8109

Please sign in to comment.
You can’t perform that action at this time.