Commit 72ad60b1 authored by cc201010's avatar cc201010
Browse files

fetch all the Pokemon and also store them in the local storage

parent 0f0a2e12
......@@ -17,14 +17,27 @@ export default{
list:[]
}
},
methods:{
async fetchPokemon(){
const url = 'https://pokeapi.co/api/v2/pokemon?limit=151'
const data = await fetch(url);
const pokemon = await data.json();
this.list = await pokemon.results;
async mounted(){
const localData = localStorage.getItem('pokemon')
if(localData){
this.list = JSON.parse(localData)
return console.log("from storage")
}
const url = 'https://pokeapi.co/api/v2/pokemon?limit=151';
const data = await fetch(url);
const pokemon = await data.json();
localStorage.setItem('pokemon',JSON.stringify(pokemon.results))
console.log('from fetch')
this.list = pokemon.results;
},
// async fetchPokemon(){
// const url = 'https://pokeapi.co/api/v2/pokemon?limit=151'
//
// const data = await fetch(url);
// const pokemon = await data.json();
// this.list = await pokemon.results;
// }
}
</script>
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment