I have the following Pokemon.vue file:
<template>
<div class="pokemon">
<h1>Pokemon Overview</h1>
<div class v-for="pokemon in pokemonArray" :key="pokemon.id">
<p>{{ pokemon.name }}</p>
<p>{{ pokemon.number }}</p>
<p>{{ pokemon.height }}</p>
<p>{{ pokemon.weight }}</p>
<p>{{ pokemon.types }}</p>
</div>
<button @click="AddPokemon">AddPokemon</button>
</div>
</template>
<script>
import axios from "axios";
import db from "@/firebase/init";
export default {
name: "Pokemon",
data() {
return {
pokemonArray: [],
};
},
methods: {
CapitalizeFirstLetter(string) {
return string.charAt(0).toUpperCase() + string.slice(1);
},
AddPokemon() {
for (var i = 520; i < 524; i++) {
axios.get("https://pokeapi.co/api/v2/pokemon/" + i).then((response) => {
var types = [];
for (var j = 0; j < response.data.types.length; j++) {
types.push(response.data.types[j].type.name);
}
db.collection("pokemon").add({
number: i,
name: CapitalizeFirstLetter(response.data.name),
weight: response.data.weight / 10,
height: response.data.height / 10,
types: types,
image:
response.data.sprites.other["official-artwork"].front_default,
});
});
}
},
},
created() {
//Fetch data from the firestore
db.collection("pokemon")
.get()
.then((snapshot) => {
snapshot.forEach((doc) => {
let pokemon = doc.data();
this.pokemonArray.push(pokemon);
});
});
},
};
</script>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
</style>
However, when I click the button that runs the AddPokemon function I get hit with
CapitalizeFirstLetter is not defined at eval
And I don't understand why this is happening. I'm clearly missing something, but to my understanding it should be fine to use a different method from "methods", but this might not be the case? Any help is greatly appreciated.