Тёмный

One UNIQUE Way to Use Teleport in Vue 3 

LearnVue
Подписаться 49 тыс.
Просмотров 20 тыс.
50% 1

The most common way to use Teleport is to create modals, but here's a use case that you might not have realized...
Github Repo: github.com/Lea...
✅ FREE VUE 3 CHEATSHEET WITH ESSENTIAL CODE SNIPPETS
learnvue.co/vu...
follow me on twitter:
/ mattmaribojoc
🚨 Like quick Vue lessons like these? Check out 800+ lessons over on Vue School - go.learnvue.co...
Music
Lukrembo - Bake a Pie
• lukrembo - bake a pie ...
Lukrembo - Wine
• lukrembo - wine (royal...

Опубликовано:

 

1 окт 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 29   
@tomparke2407
@tomparke2407 2 года назад
I understand this is trying to showcase teleport but I would actually advise simply using css grid for this. You wouldn't need to declare anything twice or use any v-if conditions. You wouldn't even need an empty tagged div. Simply stack the title, article and aside as they are with an id and use grid-template-areas with an extra media query. This is one of those display areas where I really don't think we should use JS to solve something CSS is capable of handling.
@LearnVue
@LearnVue 2 года назад
I agree that in this simple example, a css grid would also make sense. Maybe a more clear example that shows the value of teleport would be inserting the table of contents after the first X paragraphs. That's how I'm using it in my project, at least. But really appreciate the comment - good note for me to take away and provide more valuable examples for future vids :)
@tomparke2407
@tomparke2407 2 года назад
​@@LearnVue I think you broke the concept down to a simple example which is exactly what you should do when teaching a concept. I'm just flagging this for a beginner who might overcomplicate something as simple as this example. And for those guys here's the css: main { display: grid; grid-template-columns: 1fr; grid-template-areas: "header" "sidebar" "article" } header { grid-area: header; } article { grid-area: article; } aside { grid-area: sidebar } @media screen and (min-width: 400px) { main { grid-template-columns: 1fr 1fr 1fr; grid-template-areas: "header header sidebar" "article article sidebar" } }
@markthomasnoonan
@markthomasnoonan 2 года назад
I think teleport is still a good idea in this scenario. The CSS grid changes the visual order but not the logical order. Screen readers will announce the content in whatever the DOM order is, and tab key will tab to interactive content in that order as well. So imo while changing layouts with CSS at various breakpoints is fine, if those changes affect the _order_ of elements, we need to think about the effect on assistive technology. Changing the actual DOM may be the correct move even if you can achieve the same visual result with CSS.
@dusancankovic736
@dusancankovic736 2 года назад
@@markthomasnoonan Nowadays, discussions like these give me a hard on :D Good food too! :D It comes with age :D Meta thinking ;) But for beginners, grid it is I think.
@heroe1486
@heroe1486 Год назад
​​​​​​@@tomparke2407the teleport example is way simpler and intuitive than the CSS equivalent you wrote, and most devs .. beginners even more (since that's your concern) don't really dig into CSS (thus tailwind's popularity) and would prefer the JS solution. When there's some non straightforward logic involved it's always JS for me, no clever new CSS nor sass or whatever.
@Andrey-il8rh
@Andrey-il8rh 13 дней назад
Big Disclaimer: None of this is applicable if you use SSR type application (e.g. Nuxt) because: - Teleported content won't be SSRed - useBreakpoints will produce a hydration mismatch because there is no "window" object in the server context thus resulting in undefined So this approach can only be used in non-SSR apps or if the content that's affected is not SSR critical and can be wrapped in
@youssefelshahawy8080
@youssefelshahawy8080 2 года назад
don't mind me editing on my project literally every time you post something new. love your videos.
@LearnVue
@LearnVue 2 года назад
haha dont worry - im out here editing my projects when i find these tips too :)
@soviut303
@soviut303 2 года назад
Good to get people thinking about other use cases for teleport, though I agree with other comments saying this should be done entirely with CSS. That said, I think a similar example that could only be done with teleports is injecting buttons/content from a child page into its parent layout. This approach avoids complex multi-component router config and allows page-specific code to be called from those buttons.
@ConceptismoHD
@ConceptismoHD Год назад
Perfect for drag and drop of components
@johnnybravohonk6964
@johnnybravohonk6964 2 года назад
Personally, I would solve it with CSS order instead unless sidebar contains something below ToC that would need to go below the article (e.g. ads, tags or related content)
@LearnVue
@LearnVue 2 года назад
the use case you just mentioned is exactly what I should have added to make this click. haha - sorry about that, but hopefully this use of teleport still helps.
@trafalgarlaw6759
@trafalgarlaw6759 2 года назад
thank you so much dude you're a god
@bpospanov
@bpospanov Год назад
wooooah that was mind blowing
@dusancankovic736
@dusancankovic736 2 года назад
You rock! The place where I found use for Teleport in is when I want to display child content in parent/grandparent etc component. Example, actions bar in page component that has confirm/cancel buttons of child form, fixed at the top of page. Basically whenever I want to render in certain slots, but I dont want to spread the logic across multiple components.
@ms.crawford1335
@ms.crawford1335 10 месяцев назад
Brilliant
@Dnex94xD
@Dnex94xD 2 года назад
BROTHER, YOU ARE THE BEST!!! You oooh really helped me!! THANK YOU VERY MUCH!
@happynewyearw
@happynewyearw 2 года назад
Nice one, really good use case and demo! Thanks for sharing! your videos keep getting better and better!
@LearnVue
@LearnVue 2 года назад
thanks for watching! glad other people find this one cool
@nubuna7073
@nubuna7073 2 года назад
Thank you so much this helped a lot!!!! You saved my life
@MrIqbalTawakkal
@MrIqbalTawakkal 2 года назад
the content you created has been helpful man! keep going!
@wduandy
@wduandy 2 года назад
Can i use :to conditionally?
@juanperalta5853
@juanperalta5853 2 года назад
So amazing, thanks for all :))
@samsariworldoftrust
@samsariworldoftrust 2 года назад
thanks bro it's really help
@ScimonInTheSkies
@ScimonInTheSkies 2 года назад
I used it to create a backdrop on the parent's scope from a child component which was working as a general popup wrapper component 😅
@LearnVue
@LearnVue 2 года назад
Oooh that sounds cool - do you have a code sample?
@salahiddinediouri280
@salahiddinediouri280 2 года назад
thanks for sharing :)
@Jonathanprimaki1
@Jonathanprimaki1 2 года назад
Awesome!!!!
Далее
Vue Slots Simplified
7:25
Просмотров 55 тыс.
A Better Approach To Data Fetching In Nuxt?
4:51
Просмотров 8 тыс.
Please stop using px for font-size.
15:18
Просмотров 173 тыс.
Use Vue Teleport to Make Modals and Popups
4:55
Просмотров 31 тыс.
How Vue Keep Alive Can Improve Your App
6:45
Просмотров 29 тыс.
Building a Reusable Tabs Component with Vue Slots
8:21
Animating Vue Router Transitions in Vue 3
12:08
Просмотров 52 тыс.
Better Rendering Performance with Virtual Lists
5:59
A Few Ways to Improve Your Vue 3 Modals
3:44
Просмотров 22 тыс.