Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
cc201010
VueProject
Commits
72ad60b1
Commit
72ad60b1
authored
Nov 17, 2021
by
cc201010
Browse files
fetch all the Pokemon and also store them in the local storage
parent
0f0a2e12
Changes
1
Hide whitespace changes
Inline
Side-by-side
poke-app/src/components/pokemonComp.vue
View file @
72ad60b1
...
...
@@ -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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment