🔥 (#154) Dynamic logic and render functions
Hey! So many things to talk about today. VueJS AmsterdamVueJS Amsterdam is streaming right now and I'm sad I couldn't make it there this year! My Twitter feed is full of FOMO-inducing posts and it looks like a great time. Like I say every year: next year I'll be there! Deployment (not) FunThis week I'm doing the final polish and final push on getting the Reusable Components update out for next week (March 5th). I was running into some issues deploying an update for my course platform so I can support multiple courses. It ends up touching the entire checkout and authentication flow, so it's a big change and a risky one too. While it worked fine on my machine it wasn't cooperating in production. But I shouldn't have assumed it would — I've encountered problems like this before. It wasn't what I planned to do this week, but that's the nature of things. Regardless, I'm having fun with this and I'm so glad I still get to write code each week, even though my job is "creating content". It's also my birthday today! 🎉 (and no, if I was born a day later it would've been March 1st) Today I am the oldest that I've ever been. — Michael Vue Tips Collection 2Maybe you just want to stay on top of the latest features, remind yourself of interesting things Vue can do, and get daily inspiration. Vue Tips Collection is a beautiful book of 118 concise tips, as well as a daily email to get your creative juices flowing. 🔥 Using Render Functions for Dynamic Component LogicRender functions provide a powerful and flexible way to programmatically define the output of components. This approach is particularly useful when you need more control over the rendering process than templates offer. Consider a scenario where you're building a custom Here's a simplified example of how you might use a render function in an In this example, the Render functions are especially useful when:
While render functions offer great power and flexibility, they come at the cost of reduced readability and simplicity compared to template syntax. So it's generally recommended to use them only when necessary, keeping the balance between functionality and maintainability. 🔥 Nesting Reactive ObjectsHere's a nuance to nesting reactive objects that's tripped me up. Nesting a But putting this I gave a hint in that last sentence — this is because it's being wrapped in a non-reactive object. The trail of reactivity goes cold once we hit this object, but only because we're accessing the If we instead access the Of course, this isn't about refs in particular. All we need is to keep the reactivity alive, which we can also achieve using 🔥 Using unstorage in Nuxt 3Nitro, the server that Nuxt 3 uses, comes with a very powerful key-value storage system: It's not a replacement for a robust database, but it's perfect for temporary data or a caching layer. One great application of this "session storage" is using it during an OAuth flow. In the first step of the flow, we receive a We need to store the The first step in the Then we retrieve it during the second step in the A simple and easy solution, with no need to add a new table to our database and deal with an extra migration. This just scratches the surface. Learn more about the 📜 SSR Safe Dynamic IDs in VueDynamic IDs are useful for testing, but can get tricky with SSR. In this article we'll make a directive to do this easily, in both vanilla Vue and in Nuxt. Check it out here: SSR Safe Dynamic IDs in Vue 💬 Frustation"Give someone a program, you frustrate them for a day; teach them how to program, you frustrate them for a lifetime." — David Leinweber 🧠 Spaced-repetition: Debugging TemplatesThe 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. If you ever need to debug what's happening inside of a template, you can just throw in a function: Vue will execute anything within the curly braces as Javascript, so this function is called normally. It can be whatever you want. Set it to Or add in a If we want global access to a debugging utility, we can use the Now, we can use this
|
评论
发表评论