Dynamic Components in Vue

  Рет қаралды 7,919

Alexander Lichter

Alexander Lichter

Күн бұрын

Пікірлер: 54
@TheAlexLichter
@TheAlexLichter 4 ай бұрын
Whoops, no premiere today folks but still a helpful video! Let me know if it helps 🙌🏻
@codedjango
@codedjango 4 ай бұрын
sure...it helps...wasn't aware of the global style of importing components....thanks for this video 👍
@tolgabeyazoglu536
@tolgabeyazoglu536 4 ай бұрын
Like your previous video on how to use the lazy component, this is a very useful video thank you
@TheAlexLichter
@TheAlexLichter 4 ай бұрын
Happy I could be of help ☺️
@svenvanreenen
@svenvanreenen 4 ай бұрын
Great video Alex! Mine was really using an old JS switch case to render components dynamically but will definitely see how this can improve the case.
@TheAlexLichter
@TheAlexLichter 4 ай бұрын
Thank you Sven 🙏🏻 Glad I could help improving your project ☺️
@lbmgary
@lbmgary 4 ай бұрын
Love this video. For our CMS we allow the editor to select the components that will be present on any given page. To handle that we use vite to inject at build time all of these special components that our customer has access to use. Pretty simple. I really wish we could use a variable in resolve but it's probably due to knowing what component is needed at build time. idk, maybe there is another more elegant way b/c with enough components it gets a little messy on the output with all those Lazy components waiting to pop off.
@Wojtasvx
@Wojtasvx 4 ай бұрын
I think you could simplify {{ isSwitched ? "True" : "False" }} to just {{ isSwitched }}
@TheAlexLichter
@TheAlexLichter 4 ай бұрын
Yes indeed! I am mainly used to output strings because of variables being undefined and then nothing is logged. But if it definitely is a Boolean yes 👌🏻
@DontFollowZim
@DontFollowZim 4 ай бұрын
Unless of course you want it capitalized
@Gornius
@Gornius 4 ай бұрын
Had no idea that Lazy components existed, but they are so useful!
@TheAlexLichter
@TheAlexLichter 4 ай бұрын
Right? Perf-wise really helpful ☺️
@swissmexxa
@swissmexxa 4 ай бұрын
Problem in Nuxt, if you use a dynamic component and use useFetch (or useAsyncData) in the dynamic loaded component, the useFetch won‘t recognize the payload key in the DOM while hydrating and refetch the data on hydration. This is a big problem when working with storybloks own dynamic component. We had to create a wrapper around useFetch because of this.
@TheAlexLichter
@TheAlexLichter 4 ай бұрын
This sounds like a bug to me (remembered sth around that) - is there an open issue for it? If not, please raise one!
@aureutraccoredge6227
@aureutraccoredge6227 Ай бұрын
Could you elaborate on the wrapper you built? I am having a very similar problem and have been struggling to find an answer (also, Alex, thank you for the videos! learning so much)
@TarasShabatin
@TarasShabatin 4 ай бұрын
I guess the better name would be isAnotherDynamicComponentShown or isAnotherDynCompShown instead of isSwitched. Your variables' names must represent what it is storing. Your methods' names must represent what those methods are doing. Long live to Uncle Bob and "Clean Code".
@TheAlexLichter
@TheAlexLichter 4 ай бұрын
In a real world codebase 100% 👌🏻 In this example I wanted to keep it short 😁
@korbinperry6906
@korbinperry6906 3 ай бұрын
By chance could you elaborate just a little, you mentioned the "flash avoidance strategy" and I perked up a bit. Our fairly large site has just migrated to Nuxt and we've experienced some flashing, I suspect mostly actually due to SSR / CSR issues and some changes we need to make, but perhaps this is more common than I know 😅
@TheAlexLichter
@TheAlexLichter 2 ай бұрын
Ah, that's just some CSS to make it "automatically dark" and not have a "white -> dark" scenario. In actual apps, I'd probably go for the color mode module!
@shakur_t
@shakur_t 4 ай бұрын
This was a very great and useful video, thank u for sharing it
@TheAlexLichter
@TheAlexLichter 4 ай бұрын
You are welcome 🙌🏻
@valacshiro378
@valacshiro378 4 ай бұрын
Amazing and helpful as always, love this videos keep it going :D Thank you very much for the time a effort to make this. I always leran something new 😊
@TheAlexLichter
@TheAlexLichter 4 ай бұрын
Really happy the videos help 🙏🏻 Glad I can contribute to the Vue and Nuxt community ☺️
@prishanf
@prishanf 4 ай бұрын
Awesome video Alex. Thanks for all the good content.
@TheAlexLichter
@TheAlexLichter 4 ай бұрын
Thank you 🙏🏻 Happy that my content is helpful ☺️
@beia-rl2dw
@beia-rl2dw 4 ай бұрын
Awesome video, it is very helpful for me!!!
@TheAlexLichter
@TheAlexLichter 4 ай бұрын
Glad it helped! 🙌
@designerjehovah4453
@designerjehovah4453 4 ай бұрын
Great video. Personally and I'm ashamed to say it but I've never used the to render dynamic components but rather the if/else statement. I really want to learn these tidbits of knowledge and more
@lovelyboy8056
@lovelyboy8056 4 ай бұрын
This is because you didn’t met in a job cases where this dynamic components really need.
@TheAlexLichter
@TheAlexLichter 4 ай бұрын
if/else works for simple scenarios but as soon as you have "a couple of" components, sometimes with the same props, `` will come in super handy.
@Wojtasvx
@Wojtasvx 4 ай бұрын
Very good tutorial, I am waiting for more!
@TheAlexLichter
@TheAlexLichter 4 ай бұрын
Thanks a lot 🙏🏻 More is coming! 🔥
@KuroManX
@KuroManX 4 ай бұрын
Vue dynamic components + Strapi dynamic zones, best combo for a CMS.
@TheAlexLichter
@TheAlexLichter 4 ай бұрын
Would love to see unlimited nesting of dynamic zones though (e.g. like storyblok allows) 🔥
@Aguycalledmax
@Aguycalledmax 4 ай бұрын
How would you handle dynamic components if they accepted different props? Is there a way to pass props within resolvecomponent or would you use something like a computed v-bind?
@TheAlexLichter
@TheAlexLichter 4 ай бұрын
I think I'd use a computed, yes 👍🏻
@EvestDev
@EvestDev 4 ай бұрын
Well, i have some code to update XD. Thx a bunch for the video ❤️
@TheAlexLichter
@TheAlexLichter 4 ай бұрын
No problem at all! 😊
@lbmgary
@lbmgary 4 ай бұрын
lol, like every time I watch something from this jerk... :)
@sandros94
@sandros94 4 ай бұрын
Now I'm curious if it is possible to set components as global when they come from a module/layer
@TheAlexLichter
@TheAlexLichter 4 ай бұрын
Yes, when you are in control of the module you can do so. Otherwise, you can also use a Nuxt hook to adapt that but it is a bit more manual work.
@caiovinicius2718
@caiovinicius2718 2 ай бұрын
ammmmmmmmmmmmmmmazing
@TheAlexLichter
@TheAlexLichter 2 ай бұрын
Happy it helped! 🙏
@VladyslavOstapko
@VladyslavOstapko 4 ай бұрын
Thanks!
@TheAlexLichter
@TheAlexLichter 4 ай бұрын
No problem! ☺️
@adiprimanto8871
@adiprimanto8871 4 ай бұрын
anybody know how to make webpage builder? is there any library recommendations ?
@muratozalp3763
@muratozalp3763 4 ай бұрын
Most time i dont have a boolean variable to switch components. For example let us say i have menu and select menu item or tab item. I need to change component according to menu key. In this situation, i will have to put switch case for every menu option because this won't work with dynamic variables such as resolveComponent(menuItemKey). Am i right?
@TheAlexLichter
@TheAlexLichter 4 ай бұрын
Yes, a switch/case or (IMO better) a map with dynamic imports mapped to names of the components so you still have the lazy-loading benefits (in plain Vue)
@macawls
@macawls 4 ай бұрын
@@TheAlexLichter Is this a good approach? I did this very recently for a project import * as Tabs from "../components/user-profile/tabs"; import { Heart, Users, Settings, SlidersHorizontal, DollarSign, } from "lucide-vue-next"; export const useProfileRoutes = () => { const router = useRouter(); return { tabs: { favourites: { name: "favourites", content: Tabs.Favorites, icon: Heart, }, friends: { name: "friends", content: Tabs.Friends, icon: Users, }, settings: { name: "settings", content: Tabs.Settings, icon: Settings, }, preferences: { name: "preferences", content: Tabs.Preferences, icon: SlidersHorizontal, }, donate: { name: "donate", content: Tabs.Donate, icon: DollarSign, }, }, navigateToTab: (tabName: string) => { router.push({ path: "/profile", query: { tab: tabName } }); }, }; };
@РодионГаврилов-ч9ж
@РодионГаврилов-ч9ж 4 ай бұрын
haha)) its broken O.O
@ubaydillah1535
@ubaydillah1535 4 ай бұрын
i fans antfu
@TheAlexLichter
@TheAlexLichter 4 ай бұрын
We all admire him 🔥
Composition API vs. Options API - One API to Rule Them All?!
26:18
Alexander Lichter
Рет қаралды 4,4 М.
ShadCN’s Revolutionary New CLI
12:11
Jack Herrington
Рет қаралды 50 М.
Watermelon magic box! #shorts by Leisi Crazy
00:20
Leisi Crazy
Рет қаралды 79 МЛН
哈莉奎因怎么变骷髅了#小丑 #shorts
00:19
好人小丑
Рет қаралды 56 МЛН
Как мы играем в игры 😂
00:20
МЯТНАЯ ФАНТА
Рет қаралды 3,4 МЛН
规则,在门里生存,出来~死亡
00:33
落魄的王子
Рет қаралды 28 МЛН
Organize your Composition API code (2k subscriber special)
18:22
Alexander Lichter
Рет қаралды 23 М.
5 Patterns for Better Components in Vue.js - Michael Thiessen
29:08
VueConf Toronto
Рет қаралды 7 М.
The BEST way to proxy your API in Nuxt
21:12
Alexander Lichter
Рет қаралды 17 М.
BEWARE these Laravel attributes | Real World Laravel
19:10
Sam Lewis
Рет қаралды 4,5 М.
Run ALL Your AI Locally in Minutes (LLMs, RAG, and more)
20:19
Cole Medin
Рет қаралды 125 М.
The Difference Between Vue and React
10:27
Lachlan Miller
Рет қаралды 38 М.
Why you should use useState()
17:57
Alexander Lichter
Рет қаралды 18 М.
Is your function REALLY a Vue composable?
10:53
Alexander Lichter
Рет қаралды 11 М.
Why is Vite Everywhere? | Evan You
38:32
OpenSauced
Рет қаралды 34 М.
The Most Important Design Pattern in React
35:04
Cosden Solutions
Рет қаралды 63 М.
Watermelon magic box! #shorts by Leisi Crazy
00:20
Leisi Crazy
Рет қаралды 79 МЛН