🔥 (#157) Dedupe fetches easily
Hey! Today is the last day to get the newly updated Reusable Components for 35% off. You can get instant access to Reusable Components here. Other than that, I hope you're having a lovely early spring! Enjoy these tips. — Michael 🔥 Dedupe fetches in NuxtSince 3.9 we can control how Nuxt deduplicates fetches with the The However, you can change this behaviour to instead This gives us greater control over how our data is loaded and requests are made. 🔥 Nuxt Layout FallbackIf you're dealing with a complex web app in Nuxt, you may want to change what the default layout is: Normally, the This is great for large apps where you can provide a different default layout for each part of your app. 🔥 Debug hydration errors in production NuxtHydration errors are one of the trickiest parts about SSR — especially when they only happen in production. Thankfully, Vue 3.4 lets us do this. In Nuxt, all we need to do is update our config: If you aren't using Nuxt, you can enable this using the new compile-time flag: This is what Nuxt uses. Enabling flags is different based on what build tool you're using, but if you're using Vite this is what it looks like in your Turning this on will increase your bundle size, but it's really useful for tracking down those pesky hydration errors. 📜 Server Routes in Nuxt 3Server routes are a powerful feature of Nuxt 3 that allow you to create custom endpoints for your app. In this article I look at the different types of server routes and how to use them. Check it out here: Server Routes in Nuxt 3 💬 Brute force"When in doubt, use brute force." — Steve McConnell 🧠 Spaced-repetition: Reactivity and CallbacksThe best way to commit something to long-term memory is to periodically review it, gradually increasing the time between reviews 👨🔬 Actually remembering these tips is much more useful than just a quick distraction, so here's a tip from a couple weeks ago to jog your memory. Callback is a bit of a dirty word in Vue, but there are great use cases for them. Consider a scenario where a parent component needs to react to changes in its children's state. You can use a reactive object provided by the parent and injected by the children to keep track of changes. Here's an example: When a child component updates a property of You can use callbacks to allow child components to register themselves with the parent or to signal the parent to perform an action. Here's how you might implement a callback with This pattern is powerful for creating complex interactions between components while keeping the logic encapsulated and manageable. It's especially useful in the Compound Components pattern.
|
评论
发表评论