Nuxt 3 Crash Course #8 - Fetching Data

  Рет қаралды 83,613

Net Ninja

Net Ninja

Күн бұрын

In this Nuxt 3 tutorial, we'll fetch data from a 3rd party api and inject it into our components.
⭐⭐ Watch the whole course now (without ads) on Net Ninja Pro:
netninja.dev/p...
🐱‍💻 Access the course files on GitHub:
Course files - github.com/iam...
🐱‍💻 Vue 3 Tutorial:
On Net Ninja Pro - netninja.dev/p...
On KZbin - • Vue JS 3 Tutorial for ...
🐱‍💻 Tailwind Tutorial:
On Net Ninja Pro - netninja.dev/p...
On KZbin - • Tailwind CSS Tutorial ...
🐱‍💻 Nuxt Docs - code.visualstu...
🐱‍💻 VS Code - v3.nuxtjs.org/...

Пікірлер: 80
@gabrielmihai396
@gabrielmihai396 Жыл бұрын
For those who wonder why useFetch works even without providing a key, it's because now useFetch uses the uri as the key. But you can still provide a key if you need to
@jessicagosselin
@jessicagosselin Жыл бұрын
Thank you; I was coming to the comments to see if anyone said anything about this, because my requests worked just fine without a key. That is good to know, thanks!
@ProfesorCafe
@ProfesorCafe Жыл бұрын
just what I was looking for, thanks Gabriel
@nemanjarackovic2448
@nemanjarackovic2448 11 ай бұрын
But now, when i visit product page with same id twice or more, every time request is sent to api? I mean isn't all idea to cache same request, in order to avoid multiple server calls?
@rycka7260
@rycka7260 9 ай бұрын
@@nemanjarackovic2448 of course it is, and that's your job to do it... tbh, we have all product data already fetched in '/products' page. If data doesn't change that much and you don't need real-time data flow, you can just pass product data from '/products' to product details page. Only if users navigates straight to product details page, then you do fresh fetch.
@Taki7o7
@Taki7o7 3 ай бұрын
many thanks for clarification
@mitosymicrochips
@mitosymicrochips Жыл бұрын
This is by far the best crash course on the subject on KZbin. Thanks!!!
@NetNinja
@NetNinja Жыл бұрын
Thanks for the kind words Ignacio :)
@Kingside88
@Kingside88 Жыл бұрын
unfortunatly this is not the real world. In the real world you need somehow to extend it. Because a) You have a baseUrl in the config file for your'e api b) You have different header data like authorization, accept-language etc. which you need to provide every request c) Often you have to cache your'e data in a store like Pinia. So it would be very thankful, if you could extend this tutorial what is the best practice. My feeling with nuxt 3 so far is, you'll find 1000 tutorials how to create a super fancy hello world page. But nobody cares abour real process solutions. Like authorization
@moretagsgaming8172
@moretagsgaming8172 Жыл бұрын
If you are searching for best practices, the best source should be the Nuxt 3 documentation about the useFetch composable. In their example, you can do b) and c) with interceptors, which are pretty easy to write.
@aigabuskira165
@aigabuskira165 Жыл бұрын
my solution for this is to use $fetch and what ever you've fetch, save them into useState(your_key), the state data will be transferred to browser, to access the data again in the browser just use useState(your_key) with the same key. why i use $fetch? i have no idea about other solution, but i came up with use $fetch to make interceptor by wrapping it in custom composable function. sry for my bad english
@kresnaagisna3995
@kresnaagisna3995 Жыл бұрын
Yo, I just get into Nuxt. Any suggestion of better tutorial than this one?
@eotikurac
@eotikurac Жыл бұрын
@@moretagsgaming8172 nuxt docs is garbage. you can spend all day looking for a solution that might not even be there and if it is, very often the answer is well hidden or in some weird footnote you wouldn't bother looking at.
@DesertCookie
@DesertCookie 8 ай бұрын
@@kresnaagisna3995 This one is pretty good to get you started. However, you absolutely need to read through the documentation of useFetch, useLazyFetch, etc. On there, they have an composable that adds the base URL and authorization headers like moretagsgaming8172 said.
@mickeymegabyte
@mickeymegabyte Жыл бұрын
another great course from our beloved Net Ninja! one thing, i didn't need to add the {key: id} to my useFetch method - extra network requests worked fine without it, at least for me :)
@chunkycheese73
@chunkycheese73 Жыл бұрын
I think it has been patched
@LS-jv4uh
@LS-jv4uh 11 ай бұрын
At 9:00, perhaps Nuxt has improved the default behavior since you made this video? I didn't have the problem described even before I added the key.
@FacundoColombier
@FacundoColombier 4 ай бұрын
same here
@alanreibel1732
@alanreibel1732 Жыл бұрын
{ key: id} as a second argument for useFetch seems to be not needed anymore
@danielwatson6529
@danielwatson6529 Жыл бұрын
do u have an example plz?
@alanreibel1732
@alanreibel1732 Жыл бұрын
Yes @Daniel Watson , as you can see in the last minute of this video, he's passing de key as a second argument of the Fetch function. I tried without it and it works for me. An example of this could be: - Before: useFetch( uri, { key: id}) - Now: useFetch( uri)
@sahandsepidar4089
@sahandsepidar4089 Жыл бұрын
Agreed
@TemurbekValiev27
@TemurbekValiev27 Жыл бұрын
@@alanreibel1732 thank you
@daroathdaroath
@daroathdaroath 3 ай бұрын
{key: id} no longer work for newer version
@eotikurac
@eotikurac Жыл бұрын
you should expand on data fetching and show how to handle errors. i know you always skip this part but it's very important and you only need to do it once. people who have jobs in the real world also have real world problems that they cannot work out by following your tutorials.
@MetaBlueAvatar
@MetaBlueAvatar Жыл бұрын
Hi Shaun, thank you for this wonderful crash course. It's helping me get up to speed with Nuxt 3 quickly. I tried the above code on my local but found that fetch is making a new call even without the key property being added to the useFetch composable. As per your your video this is not the intended behaviour. Has something changed recently?
@misschantalbelle
@misschantalbelle Жыл бұрын
Same thing for me
@bouchrabenghazala9508
@bouchrabenghazala9508 Жыл бұрын
In 9:28 it worked for me, I see different products when going to the product details. I don't know why it didn't work for you at first. Thank you!
@kitephan9533
@kitephan9533 Жыл бұрын
The same with you. Still don't know why
@yabuking84
@yabuking84 Жыл бұрын
Actually didnt need to use key. Was there an update on useFetch?
@연이-n7v
@연이-n7v Жыл бұрын
thank you very much! i want to know difference between useFetch() and asyncDataFetch() :)
@diegoavendanohernandez9908
@diegoavendanohernandez9908 Жыл бұрын
Perfect, exactly what I needed. Love it.
@sandeshmaharjan8204
@sandeshmaharjan8204 Жыл бұрын
Am getting error, it won't render the page and after reloading the page am getting error saying that Cannot read property of null (reading 'title')
@nickiminaj0882
@nickiminaj0882 5 ай бұрын
same, did you fix it?
@Lerndemy
@Lerndemy Жыл бұрын
thanks a lot, next series on next 13 ❤❤
@diegoavendanohernandez9908
@diegoavendanohernandez9908 Жыл бұрын
yes!
@worldwidelibra
@worldwidelibra Жыл бұрын
all the tutorials I have came across states that this should work but when I attempt it just tells me products is not defined
@victorhytrop
@victorhytrop 6 ай бұрын
Hey bro! I really want to watch your whole course, but I have troubles with payment system, can I pay by ETH or USDT to you directly? Peace
@ak-loz
@ak-loz Жыл бұрын
Why make a fetch request at: `products/` and then another at: `products/:id` Can’t we reduce the requests made here? It’s running slow for me now, there should be a way to optimize that into a single call and just push the necessary information into the page?
@mohammadaliafrasiaby2347
@mohammadaliafrasiaby2347 Жыл бұрын
very very nice but please create course about jwt in nuxt
@lancewoolf8236
@lancewoolf8236 Жыл бұрын
You are amazing man, This has helped me level up Massively! More Nuxt
@NetNinja
@NetNinja Жыл бұрын
That's great to hear, thanks Lance!
@user-xu3so2ug1f
@user-xu3so2ug1f Жыл бұрын
i get without using a key always the matching product details ... dont know what i made wrong, also if i go to the same product twice there will both times be the api fetch
@KuroManX
@KuroManX Жыл бұрын
Is there a way to save the data requested on the products and pass that data directly to the products/${id}, so I can save requests and time?
@musafirfisabillah6566
@musafirfisabillah6566 Жыл бұрын
Hi teach in course 8 when I click on the different product I receive different data back from api . Maybe that but has been patch . btw You are doing and great jobs please put out more nuxt 3 video
@shazamanything3583
@shazamanything3583 Жыл бұрын
Can I use your HTML CSS and JavaScript courses for 2023?
@Realswagoverlord
@Realswagoverlord Жыл бұрын
yes
@formixcode
@formixcode 10 ай бұрын
need more nuxt3 real life projects course
@Tokieejke
@Tokieejke Жыл бұрын
Hi bro, how can i refetch poroducts every time when my locale with i18n changed? i need to refetch products with specified language from strapi
@mel-182
@mel-182 Жыл бұрын
I love you man!
@NetNinja
@NetNinja Жыл бұрын
@aqordeon
@aqordeon Жыл бұрын
I write the same code for fetching data but it did fetch request each page (list products page and product page). Why?
@erpethiopia
@erpethiopia Жыл бұрын
how to render product image? in addition how to use pagination or infinite scroll for fetching api? thank you!
@zuhieralif2450
@zuhieralif2450 Жыл бұрын
My Grid class doesn't seems to exist inside my nuxt project. Anyone care for a help?
@techwithdavid
@techwithdavid Жыл бұрын
Thanks 🙏🔥
@abbeed1
@abbeed1 Жыл бұрын
thanks
@caglaracar5123
@caglaracar5123 Жыл бұрын
Thanksss !
@nested9301
@nested9301 Жыл бұрын
i'm confused why u are fetching data in the components u should create an api folder in the server folder and then fetch the data using $fetch in the server then use useFetch to hit your endpoint and grab all the products ..." i'm I missing something?"
@rycka7260
@rycka7260 9 ай бұрын
yes, you are missing the point of Vue.js
@RustyRustacean
@RustyRustacean Жыл бұрын
if you are grabbing the ID from the route, what need was there to bind the ID? i mean this: :to="`/products/${p. id)`"
@musafirfisabillah6566
@musafirfisabillah6566 Жыл бұрын
and I didnt need to use the key at all
@Cho1279624
@Cho1279624 Жыл бұрын
Neither did I
@dulshansamarakoon5068
@dulshansamarakoon5068 Жыл бұрын
LOVE YOU brother
@NetNinja
@NetNinja Жыл бұрын
Thanks Dulshan!
@nghiahuy3935
@nghiahuy3935 Жыл бұрын
How can i add auth token in header ?
@yabuking84
@yabuking84 Жыл бұрын
what about useLazyFetch?
@_Mafia_
@_Mafia_ Жыл бұрын
FakeStoreApi is created by an Iranian Programmer. In hope for Freedom in Iran.❤🕊
@wovasteengova
@wovasteengova Жыл бұрын
7:55 😂😂
@towatch
@towatch Жыл бұрын
✌🏻✌🏻🔥
@sayoko5362
@sayoko5362 Жыл бұрын
why not use Axios?
@dannydevs
@dannydevs Жыл бұрын
useFetch is built in and has stuff under the hood that's as good as what Axios does (e.g. no need to convert data to JSON, useFetch does it automatically for you). so why not use useFetch?
@KadekRestuSatyaWardanaRestuSat
@KadekRestuSatyaWardanaRestuSat Жыл бұрын
im going to ninja
@EAbdoAhmedSayed
@EAbdoAhmedSayed Жыл бұрын
Egyptian announced 11/ 11 a revolution against the decorators alsis Could you speak about Our Egyptian revolution
@larsnobel4279
@larsnobel4279 6 ай бұрын
'__VLS_ctx.product' is of type 'unknown'.ts-plugin(18046) Property 'title' does not exist on type 'never'.ts-plugin(2339) I tried to directly clone your repository and in my own.
@larsnobel4279
@larsnobel4279 6 ай бұрын
What the actually fuck. Closing the application and restarting VScode resolved the issue? Never tried that before.
@ziyoxojasultonov2883
@ziyoxojasultonov2883 Жыл бұрын
💯
@JJ-je4mz
@JJ-je4mz Жыл бұрын
This course helped me finally getting started with vue/nuxt, everything just works great
@NetNinja
@NetNinja Жыл бұрын
That's awesome, thanks for watching JJ :)
Nuxt 3 Crash Course #9 - Reusable Components
11:47
Net Ninja
Рет қаралды 54 М.
Creating APIs in Nuxt with Daniel Roe
33:33
Treblle
Рет қаралды 12 М.
Electric Flying Bird with Hanging Wire Automatic for Ceiling Parrot
00:15
АЗАРТНИК 4 |СЕЗОН 2 Серия
31:45
Inter Production
Рет қаралды 1 МЛН
МЕБЕЛЬ ВЫДАСТ СОТРУДНИКАМ ПОЛИЦИИ ТАБЕЛЬНУЮ МЕБЕЛЬ
00:20
Whoa
01:00
Justin Flom
Рет қаралды 61 МЛН
Data Fetching With Nuxt 3
20:31
John Komarnicki
Рет қаралды 32 М.
Mastering Advanced Nuxt.js with Daniel Roe
1:19:33
This Dot Media
Рет қаралды 10 М.
Nuxt 3 Crash Course #12 - Server Routes
10:48
Net Ninja
Рет қаралды 40 М.
Build your own Custom Composables in Vue
12:13
Vue Mastery
Рет қаралды 41 М.
Nuxt JS Crash Course
46:08
Traversy Media
Рет қаралды 228 М.
You're Probably Using Nuxt Wrong
5:16
LearnVue
Рет қаралды 24 М.
Nuxt 3 tutorial part 1. Build a full stack app with Nuxt 3
43:58
Full Stack Jack
Рет қаралды 66 М.
Electric Flying Bird with Hanging Wire Automatic for Ceiling Parrot
00:15