[英]Cannot read properties of undefined (reading) in Vue3
I am getting this call from the famous ApiPokemon: https://pokeapi.co/api/v2/pokemon?limit=151我从著名的 ApiPokemon 接到这个电话: https ://pokeapi.co/api/v2/pokemon?limit=151
Once I have that data I want to pass it through another method ( _getPokemonData ) to map the complete data for each Pokémon.一旦我有了这些数据,我想通过另一个方法( _getPokemonData )将它传递给每个神奇宝贝的完整数据。
However when I create this VueJS method I get this error:但是,当我创建此 VueJS 方法时,我收到此错误:
Uncaught (in promise) TypeError: Cannot read properties of undefined (reading '_getPokemonData') Uncaught (in promise) TypeError: Cannot read properties of undefined (reading '_getPokemonData')
Why can't I call the _getPokemonData method inside the forEach?为什么我不能在 forEach 中调用 _getPokemonData 方法? This is my code:这是我的代码:
mounted() {
this.$http
.get("https://pokeapi.co/api/v2/pokemon?limit=151")
.then((response) => {
//this.pokemons = response.data.results;
this.pokemons = response.data.results.forEach(function(pokemon){
this._getPokemonData(pokemon);
});
});
this.$http
.get("https://pokeapi.co/api/v2/type/")
.then((response) => {
this.types = response.data.results;
});
},
methods: {
_getPokemonData(pokemon) {
console.log(pokemon);
},
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.