🔥 (#160) Magical components, pseudo-selectors, and the Vite ecosystem
What's up? I'll be giving a talk at Vue.JS Live on April 25th. You can check it out here: https://vuejslive.com/ Other than that, enjoy your tips and the rest of your week! — 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. 🔥 Creating Magic with Context-Aware ComponentsContext-aware components are "magical" — they adapt to what's going on around them automatically, handling edge cases, state sharing, and more. There are 3 main types of context-aware components, but configuration is the one I find most interesting. 1. State SharingWhen you break up a large component into smaller ones, they often still need to share state. Instead of pushing that work on whoever's consuming the components, you can make this happen "behind the scenes." To give you more flexibility, you may break up a 2. ConfigurationSometimes component behaviour needs to change based on what's going on in the rest of the application. This is often done to automagically handle edge cases that would otherwise be annoying to deal with. A This can be done automagically if the 3. StylingYou already create context-aware CSS, applying different styles based on what's happening in parent or sibling elements. CSS variables let us push this further, allowing us to set different values in different parts of the page. 🔥 Special CSS pseudo-selectors in VueIf you want some styles to apply specifically to slot content, you can do that with the You can also use Of course, if you have lots of global styles you want to add, it's probably easier to just add a second Check out the docs for more info. 🔥 Overriding styles of a child component — the right wayScoped CSS is fantastic for keeping things tidy and not accidentally bleeding styles into other parts of your app. But sometimes, you need to override the styles of a child component and break out of that scope. Vue has a In Vue 2 this has a slightly different syntax depending on which CSS pre-processor you're using: Yes, I have previously covered why you shouldn't do this, but overriding styles can be the best solution (we don't believe in "best practices" here). 📜 The Vite EcosystemVite has taken web development tooling to a new level. This article explores all of the different tools Vite uses and interacts with, and shows just how much it affects the web development community. It's very cool to see a project that started out in Vue-land gain wide adoption like this! Check it out here: The Vite Ecosystem 💬 Data structures"Bad programmers worry about the code. Good programmers worry about data structures and their relationships." — Linus Torvalds 🧠 Spaced-repetition: Default Content with Nested SlotsThe 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 have multiple levels of nested slots, it's possible to have defaults at each level: The slot content provided at the highest point in the hierarchy will override everything below it. If we render And if the component rendering the
|
评论
发表评论