【发布时间】:2020-02-10 05:55:12
【问题描述】:
我正在使用 vue / axios 使用此 Pokeapi 设置 PokeDex 项目。目前我正在使用这个 JSON 文件加载所有口袋妖怪名称:https://pokeapi.co/api/v2/pokedex/1/
我想加载来自另一个 JSON 文件的额外口袋妖怪数据。例如:https://pokeapi.co/api/v2/pokemon/bulbasaur/
除了当前的设置之外,我如何动态加载这些数据?
当前设置:
<template>
<div id="app">
<div class="pokemon" v-for="pokemon in info">
<span >{{ pokemon.entry_number }}</span>
<span >{{ pokemon.pokemon_species.name }}</span>
</div>
</div>
</template>
<script>
export default {
name: '#app',
data () {
return {
info: [],
loading: true,
errored: false,
}
},
methods: {
},
mounted () {
axios.get('https://pokeapi.co/api/v2/pokedex/1/')
.then(response => {
this.info = response.data.pokemon_entries
})
.catch(error => {
console.log(error)
this.errored = true
})
.finally(() => this.loading = false)
}
};
</script>
【问题讨论】:
-
是否有第二个 API url 是静态的,还是该 url 取决于第一次调用的结果?
-
嗨@SimonThiel,取决于第一次调用:第一个 API:pokeapi.co/api/v2/pokedex/1 第二个 API pokeapi.co/api/v2/pokemon + 'name of pokemon/' 所以我猜 'name of the pokemon' 应该填充为第一次调用的结果。
-
当您可以在第一个 API 的“then”中简单地调用它时
-
还是第一个 API 返回一个列表,您需要检索所有条目的详细信息?
-
是的,@SimonThiel,我需要检索所有条目的其他详细信息。第一个 API 只返回名称 + url。