forked from vikejs/vike-vue
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BREAKING CHANGE: Fetching data using `pageContext.pageProps` is deprecated, use `data()` and `useData()` instead, see https://vike.dev/data-fetching BREAKING CHANGE: Setting the page's title using `pageContext.title` is deprecated (`pageContext.description` and `pageContext.lang` are also deprecated), use the settings `title` and `Head` instead, see https://vike.dev/head
- Loading branch information
Showing
66 changed files
with
195 additions
and
903 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,9 @@ | ||
<template> | ||
<meta name="viewport" content="width=device-width, initial-scale=1" /> | ||
<meta name="description" content="Demo showcasing Vike + Vue" /> | ||
<link rel="icon" :href="logoUrl" /> | ||
</template> | ||
|
||
<script lang="ts" setup> | ||
import logoUrl from '../assets/logo.svg' | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,16 @@ | ||
<template> | ||
<h1>Star Wars Movies</h1> | ||
<ol> | ||
<li v-for="item in data.movies" :key="item.id"> | ||
<li v-for="item in movies" :key="item.id"> | ||
<a :href="'/star-wars/' + item.id">{{ item.title }}</a> ({{ item.release_date }}) | ||
</li> | ||
</ol> | ||
<p>Source: <a href="https://star-wars.brillout.com">star-wars.brillout.com</a>.</p> | ||
<p>Source: <a href="https://brillout.github.io/star-wars">brillout.github.io/star-wars</a>.</p> | ||
<p>Data can be fetched by using the <code>data()</code> hook.</p> | ||
</template> | ||
|
||
<script lang="ts" setup> | ||
import type { Data } from './+data' | ||
import { useData } from 'vike-vue/useData' | ||
const data = useData<Data>() | ||
const movies = useData<Data>() | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,22 @@ | ||
// https://vike.dev/data | ||
export { data } | ||
export type { Data } | ||
export type Data = Awaited<ReturnType<typeof data>> | ||
|
||
import { fetchStarWarsMovies, filterMoviesData, getTitle } from './data' | ||
|
||
type Data = Awaited<ReturnType<typeof data>> | ||
import fetch from 'node-fetch' | ||
import type { Movie, MovieDetails } from '../types' | ||
|
||
const data = async () => { | ||
const movies = await fetchStarWarsMovies() | ||
return { | ||
// We remove data we don't need because the data is passed to the client; we should | ||
// minimize what is sent over the network. | ||
movies: filterMoviesData(movies), | ||
// The page's <title> | ||
title: getTitle(movies) | ||
} | ||
const response = await fetch('https://brillout.github.io/star-wars/api/films.json') | ||
const moviesData = (await response.json()) as MovieDetails[] | ||
// We remove data we don't need because the data is passed to the client; we should | ||
// minimize what is sent over the network. | ||
const movies = minimize(moviesData) | ||
return movies | ||
} | ||
|
||
function minimize(movies: MovieDetails[]): Movie[] { | ||
return movies.map((movie) => { | ||
const { title, release_date, id } = movie | ||
return { title, release_date, id } | ||
}) | ||
} |
47 changes: 0 additions & 47 deletions
47
examples/basic/pages/star-wars/index/+onBeforePrerenderStart.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export { title } | ||
|
||
import type { Data } from './+data' | ||
import type { PageContext } from 'vike/types' | ||
|
||
function title(pageContext: PageContext<Data>) { | ||
const movies = pageContext.data | ||
return `${movies.length} Star Wars Movies` | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
<template> | ||
<h1>{{ data.movie.title }}</h1> | ||
Release Date: {{ data.movie.release_date }} | ||
<h1>{{ movie.title }}</h1> | ||
Release Date: {{ movie.release_date }} | ||
<br /> | ||
Director: {{ data.movie.director }} | ||
Director: {{ movie.director }} | ||
<br /> | ||
Producer: {{ data.movie.producer }} | ||
Producer: {{ movie.producer }} | ||
</template> | ||
|
||
<script lang="ts" setup> | ||
import type { Data } from './+data' | ||
import { useData } from 'vike-vue/useData' | ||
const data = useData<Data>() | ||
const movie = useData<Data>() | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,24 @@ | ||
// https://vike.dev/data | ||
export { data } | ||
export type { Data } | ||
export type Data = Awaited<ReturnType<typeof data>> | ||
|
||
import fetch from 'cross-fetch' | ||
import fetch from 'node-fetch' | ||
import type { PageContextServer } from 'vike/types' | ||
import { filterMovieData } from '../filterMovieData' | ||
import type { MovieDetails } from '../types' | ||
|
||
type Data = Awaited<ReturnType<typeof data>> | ||
|
||
const data = async (pageContext: PageContextServer) => { | ||
const response = await fetch(`https://star-wars.brillout.com/api/films/${pageContext.routeParams?.movieId}.json`) | ||
const response = await fetch( | ||
`https://brillout.github.io/star-wars/api/films/${pageContext.routeParams?.movieId}.json` | ||
) | ||
let movie = (await response.json()) as MovieDetails | ||
|
||
// We remove data we don't need because the data is passed to the client; we should | ||
// minimize what is sent over the network. | ||
movie = filterMovieData(movie) | ||
|
||
// The page's <title> | ||
const { title } = movie | ||
movie = minimize(movie) | ||
return movie | ||
} | ||
|
||
return { | ||
movie, | ||
// The page's <title> | ||
title | ||
} | ||
function minimize(movie: MovieDetails): MovieDetails { | ||
const { id, title, release_date, director, producer } = movie | ||
movie = { id, title, release_date, director, producer } | ||
return movie | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export { title } | ||
|
||
import type { Data } from './+data' | ||
import type { PageContext } from 'vike/types' | ||
|
||
function title(pageContext: PageContext<Data>) { | ||
const movie = pageContext.data | ||
return movie.title | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.