🔥 (#161) v-once, global properties, and callOnce in Nuxt
Hey! April has been a quieter month for me, which is nice after the busyness of the first part of this year. I'm going to be giving a talk at Vue.JS Live on April 25th, so make sure you don't miss it! You can check it out here: https://vuejslive.com/ Also, don't forget to check out the latest Deja Vue podcast episode here. As always, here are your tips. — 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. 🔥 Handle Client-side Errors in NuxtProper error handling is a crucial part of any production app, even if it isn't the most exciting thing. Nuxt 3 comes with the Use the If we pass the Use a In some cases, a more drastic action might be needed, like navigating to a safe page using the You can place This is better than simply having a generic error message that's shown no matter what the error is. By isolating errors with Learn more from the docs: https://nuxt.com/docs/api/components/nuxt-error-boundary 🔥 v-onceIf you've got large chunks of static or mostly static content, you can tell Vue to (mostly) ignore it using the This can be a helpful performance optimization if you need it. The Here are the docs for v-once. 🔥 Global PropertiesIt's possible to add global properties to your Vue app in both Vue 2 and Vue 3: I would recommend prefixing any global properties with a This helps prevent naming conflicts with other variables, and it's a standard convention that makes it easy to spot when a value is global. This global property can be accessed directly off of any component when using the Options API: Why can't this be used with the composition API? Because the composition API is designed to be context-free and has no access to Instead, you can create a simple composable to access your globals: 📜 3 Ways to Create Inline ComposablesComposables are great, except that it seems we always need to create a new file for them. In this article I explore some ways we can create inline composables — no need to create new files all over the place! Check it out here: 3 Ways to Create Inline Composables 💬 Principles of Programmer Productivity"What one programmer can do in one month, two programmers can do in two months." — Fred Brooks 🧠 Spaced-repetition: How to use callOnce in NuxtThe 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 need to run a piece of code only once, there's a Nuxt composable for that (since 3.9): Using It also has a key similar to By default Nuxt will use the file and line number to automatically generate a unique key, but this won't work in all cases.
|
评论
发表评论