[Vuejs]-Api call not working properly

0👍

Replace error with catch, as the others said:

export default {
  name: "app",
  data() {
    return {
      pokemon: {}
    };
  },
  methods: {
    requestPokemon() {
      return new Promise((resolve, reject) => {
        axios.get("http://pokeapi.co/api/v2/pokemon/2").then(value => {
          resolve(value);
        })
        .catch(error => {
          reject(error);
        })
      });
    }
  },
  beforeMount() {
    this.requestPokemon().then(value => {
      pokemon = value;
    }).catch(error => {
      console.log(error);
    })
  }
};

0👍

Your beforeMount is not correct.
As oMiKeY said in his answer, you need to change .error to .catch
You also need to bind the response to this.pokemon (and not just pokemon)
Then, as requestPokemon function returns a Promise, you need to find the data in it :

  beforeMount() {
    this.requestPokemon().then(value => {
      this.pokemon = value.data
    }).catch(error => {
      console.log(error);
    })
  }

Leave a comment