🔥 (#159) Writable computed refs, two script blocks, and Nuxt's powerful built-in storage
Hey there! I hope you're enjoying spring and all your Vue development. Don't forget to check out the latest Deja Vue podcast episode here. Also, I've got a bunch of tips for you this week. Enjoy! — 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. 🔥 Directly accessing parent components (and why)Props down, events up. That's how your components should communicate — most of the time. But in rare cases, that just doesn't work. If you need direct access to the parent component, you should just use Then, inject it into the child component: In Vue 2, you can also use the instance property This is simpler, but leads to higher coupling and will more easily break your application if you ever refactor. You can also get direct access to the application root, the very top-most component in the tree, by using When would these be useful? There are a few different scenarios I can think of. Usually, when you want to abstract some behaviour and have it work "magically" behind the scenes. You don't want to use props and events to connect up a component in those cases. Instead, you use (This is similar to the Compound Component pattern) But it's hard to come up with an example where this is the best solution. Using 🔥 Writable Computed RefsComputed refs are cool and all, but did you know you can create writable computed refs? 🔥 Using two script blocksThe This works because the There are a few reasons why you might want to do this:
Check out the docs for more info 📜 I wrote my own Vue.jsA story that most of us can relate to. When do you use an existing solution or write it from scratch yourself? Check it out here: I wrote my own Vue.js 💬 Two Types of Languages"There are only two kinds of languages: the ones people complain about and the ones nobody uses." — Bjarne Stroustrup 🧠 Spaced-repetition: Nuxt's Powerful Built-In StorageThe 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. Nitro, 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
|
评论
发表评论