iamshaunjp / sveltekit-tutorial Goto Github PK
View Code? Open in Web Editor NEWAll course files for the Net Ninja SvelteKit crash course tutorial on YouTube.
All course files for the Net Ninja SvelteKit crash course tutorial on YouTube.
when i typed in the code that you showed in the video[lesson 10]:
<script context="module">
export async function load({ page, fetch }) {
const id = page.params.id
const res = await fetch(`https://jsonplaceholder.typicode.com/posts/${id}`)
const guide = await res.json()
if (res.ok) {
return {
props: {
guide
}
}
}
return {
status: res.status,
error: new Error('Could not fetch that guide')
}
}
</script>
I got a error:
`page` in `load` functions has been replaced by `url` and `params`
Error: `page` in `load` functions has been replaced by `url` and `params`
so I use this code to check the arguments:
export async function load({ fetch}) {
console.dir(arguments);
}
and finally I know how to get the 'id' by using following code:
<script context="module">
export async function load({ fetch, params }) {
console.dir(arguments); //遇到报错的时候可以用console把参数全部打印出来看看
const id = params.id;
const res = await fetch(`https://jsonplaceholder.typicode.com/posts/${id}`);
const guide = await res.json();
if (res.ok) {
return {
props: {
guide,
},
};
}
return {
status: res.status,
error: new Error("Could not fetch the guide"),
};
}
</script>
Hopefully this can help others with the same bug.(๑′ᴗ‵๑)I Lᵒᵛᵉᵧₒᵤ❤
Hello author.
when I create a file called "__layout.reset.svelte" in your video and code.
I get a wrong info: "__layout.reset has been removed in favour of named layouts: https://kit.svelte.dev/docs/layouts#named-layouts"
and i try to rename it as "__layout-reset.svelte ". it's work!. i guess the reason is the version of sveltekit.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.