2
votes

Using Vue.Js, when I try to run on local host, I get an error of Cannot read property 'get' of undefined

It is referring to my.get request. Any advice?

export default {
  asyncData({ $axios }) {
   return $axios.get('https://jsonplaceholder.typicode.com/todos/1')
     .then(response => {
      return { posts: response.data }
    })

},
1
maybe you need to add const $axios = require('axios'); before the exportNathanael
please share the nuxt.config.js fileBoussadjra Brahim
Apart from your $axios variable being undefined, you will need to call $get instead of get.Florian Pallas
Is the @nuxtjs/axios package installed in your project and present in the modules array in the nuxt.config.js?Avraham
Did you run npm i first?tao

1 Answers

0
votes

It should be like this

asyncData({ $axios }) { return $axios.$get('https://jsonplaceholder.typicode.com/todos/1') .then(response => { return { posts: response.data } }) },

Add $get