1

I have a variable

setup: {
  const items = ref<basicPokemon[]>([]);
}

But i can't seem to get access to it in my function. I can however access it inside the 'methods' part, not inside the function. What am I doing wrong?

methods: {

this.items //this works

 let response =  axios({
              url: 'https://stoplight.io/mocks/appwise-be/pokemon/57519009/pokemon',
              method: 'get',
              timeout: 8000,
              headers: {
                  'Content-Type': 'application/json',
              }})
              .then(data => data.data.forEach(function(pok: basicPokemon){
                  try{
                    this.items.value.push(pok); //here I cannot access the variable
                
                  }
                  catch(err){
                    //todo error handling
                        console.log(err)
                  }
                }))
}
  • 1
    declare outside of `axios` call `let myvar = this.items` and try to use `myvar` inside of your `axios` call. – Rafael Oct 25 '22 at 09:07
  • 1
    `headers: { 'Content-Type': 'application/json', }})` is nonsense. Your request body isn't JSON. You don't have a request body in the first place. – Quentin Oct 25 '22 at 09:09
  • I did what Rafael said: `let list = ref(this.items)` Seems to work! – Raf Vandelaer Oct 25 '22 at 09:11

0 Answers0