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{ ...@@ -17,14 +17,27 @@ export default{
list:[] list:[]
} }
}, },
methods:{ async mounted(){
async fetchPokemon(){ const localData = localStorage.getItem('pokemon')
const url = 'https://pokeapi.co/api/v2/pokemon?limit=151' if(localData){
this.list = JSON.parse(localData)
const data = await fetch(url); return console.log("from storage")
const pokemon = await data.json();
this.list = await pokemon.results;
} }
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> </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