Skip to content

Commit a101256

Browse files
committed
nuxt-pokedex: setup grid page
1 parent fa0b133 commit a101256

File tree

5 files changed

+91
-8
lines changed

5 files changed

+91
-8
lines changed

pokedex-app/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@ Breakdown:
5151

5252
### Nuxt.js
5353

54+
Initial setup is quite straightforward. I like the fact the asset import can be managed centrally through `nuxt.config.js` instead of importing them form different components as with React/Next.js.
55+
56+
There's no clean implementation of the equivalent to `React.Fragment` (`<></>`), which seems odd since you're forced to use empty div-elements instead. (Some workarounds exist)[https://stackoverflow.com/questions/57901393/is-there-anything-like-react-fragment-in-vuejs-nuxtjs] but I would expect such a popular framework to feature this out of the box.
57+
58+
59+
60+
5461
Time to implement: ~ 0h
5562

5663
### SveleKit
Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,58 @@
1+
12
<template>
2-
<br />
3+
<div>
4+
<p v-if="$fetchState.pending">Loading...</p>
5+
<div class="grid-container">
6+
<div class="grid-search">
7+
<input
8+
id="search-input"
9+
class="input is-medium"
10+
type="text"
11+
placeholder="Search"
12+
/>
13+
</div>
14+
<div class="grid-wrapper">
15+
<a v-for="(item, index) in data" :key="index">
16+
<ItemCard :postId="getPostIdFromUrl(item.url)" :name="item.name" />
17+
</a>
18+
</div>
19+
<button class="load-more button is-primary is-fullwidth">
20+
Load More
21+
</button>
22+
</div>
23+
</div>
324
</template>
425

26+
<script>
27+
const FETCH_LIMIT = 30
28+
29+
// eslint-disable-next-line no-unused-vars
30+
export function getPostIdFromUrl(url) {
31+
return url.split('/').reverse()[1]
32+
}
33+
34+
export default {
35+
data() {
36+
return {
37+
data: [],
38+
displayData: [],
39+
searchValue: [],
40+
page: 0,
41+
}
42+
},
43+
async fetch() {
44+
const response = await fetch(
45+
`https://pokeapi.co/api/v2/pokemon?limit=${FETCH_LIMIT}&offset=${
46+
this.page * FETCH_LIMIT
47+
}`
48+
).then((res) => res.json())
49+
this.data = [...this.data, ...response.results]
50+
console.log('this.data', this.data)
51+
},
52+
methods: {
53+
getPostIdFromUrl(url) {
54+
return url.split('/').reverse()[1]
55+
},
56+
},
57+
}
58+
</script>
Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,22 @@
11
<template>
2-
<br />
2+
<div class="tile">
3+
<figure class="image">
4+
<img
5+
:src="`https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/${postId}.png`"
6+
:alt="name"
7+
/>
8+
</figure>
9+
<div class="content">
10+
<h3>
11+
<span class="prefix">#{{ postId }}:&nbsp;</span>
12+
{{ name }}
13+
</h3>
14+
</div>
15+
</div>
316
</template>
417

18+
<script>
19+
export default {
20+
props: ['name', 'postId'],
21+
}
22+
</script>
Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
<template>
22
<nav class="navigation container">
33
<div class="logo">
4-
<a class="" href="#">
5-
<img alt="Pokedex App" :src="require(`~/assets/images/pokedex-logo.png`)" width="120" />
6-
</a>
4+
<NuxtLink to="/">
5+
<img
6+
alt="Pokedex App"
7+
:src="require(`~/assets/images/pokedex-logo.png`)"
8+
width="120"
9+
/>
10+
</NuxtLink>
711
</div>
812

913
<div class="nav-items">
10-
<a class="button is-ghost">Home</a>
11-
<a class="button is-ghost">About</a>
14+
<NuxtLink class="button is-ghost" to="/"> Home </NuxtLink>
15+
<NuxtLink class="button is-ghost" to="/about"> About </NuxtLink>
1216
</div>
1317
</nav>
1418
</template>

pokedex-app/nuxt-pokedex/pages/index.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template>
2-
<Tutorial />
2+
<Grid />
33
</template>
44

55
<script>

0 commit comments

Comments
 (0)