Building a Reusable Tabs Component with Vue Slots

Поделиться
HTML-код
  • Опубликовано: 21 окт 2024
  • In this Vue 3 tutorial, we’ll be using slots to build a custom tab component that allows any sort of content to be turned into a single page tab system.
    LINKS
    Companion Article - learnvue.co/20...
    Vite Tutorial - www.youtube.co....
    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...

Комментарии • 58

  • @mohtasimhasan1928
    @mohtasimhasan1928 3 года назад +5

    Best of best😍😍. I really appreciate this video. Very natural style of explanation, anyone can understand👼🏿.

    • @LearnVue
      @LearnVue  3 года назад

      Thank you so much - those words really mean a lot :)

    • @aomo5
      @aomo5 7 месяцев назад

      i thinks so !!it's great work!

  • @yudilokhande8915
    @yudilokhande8915 3 года назад +7

    Great video! Could you also tell us how one can take a deep dive into the workings of Vue? and understand what all the different terms mean and how they can be utilised?

    • @LearnVue
      @LearnVue  3 года назад +8

      Personally, I think that for deep dives the best option is genuinely to read through the Vue documentation. I think it's one of the best documentations out there.

  • @user-uk9er5vw4c
    @user-uk9er5vw4c Год назад

    this playlist is gold

  • @ennioVisco
    @ennioVisco 2 года назад +6

    Would be cool to have an updated version (maybe even only of the article), considering how different the syntax is now with

    • @petrnadvornik9767
      @petrnadvornik9767 2 года назад +5

      for example:
      import { ref, provide, useSlots } from "vue";
      const tabTitles = ref();
      tabTitles.value = useSlots()
      ?.default?.()
      .map((tab) => tab?.props?.title);
      const selectedTitle = ref(tabTitles.value[0]);
      provide("selectedTitle", selectedTitle);

    • @martakaczmarek5412
      @martakaczmarek5412 10 месяцев назад

      @@petrnadvornik9767 thank you so much for this!

  • @teeed7927
    @teeed7927 Год назад

    great tutorial - I didn't know about setup() or provide/inject and now I know

  • @petobari6422
    @petobari6422 Год назад

    best Video, was struggling to do this since a Week. Thanks alot

  • @wooblay
    @wooblay Год назад

    Really really helpful and straight forward

  • @jadersbr
    @jadersbr 3 года назад +2

    Good job, you've got a new subscriber!

    • @LearnVue
      @LearnVue  3 года назад

      awesome! thank you

  • @mateuszmalanowski3819
    @mateuszmalanowski3819 6 месяцев назад

    Cheers mate, cool tutorial!

  • @brunomiguelgroth
    @brunomiguelgroth 9 месяцев назад

    I am learnimg dynamic components and this video was really helpful.
    One of my doubts was how to pass props to the dynamic component since @prop=" " could not be available when using different components, and you solve it using Provide/Inject.
    But one doubt still remains: is there another way to listen to events without using @emit in , since isnt all the components that will be dynamically shown that emits those events?

  • @shmert
    @shmert 3 года назад +2

    Nice! Good example of provide. Question: accessibility for tab components? Might be nice to include a bit more accessibility. Also FYI, the link to the cheatsheet is broken

    • @LearnVue
      @LearnVue  3 года назад

      Yeah - accessibility is something I would like to cover in future videos thanks for point it out.
      Also, just updated the links for the cheatsheet!

  • @Shynghys98
    @Shynghys98 2 года назад +1

    Hello, how can we add reactivity to tabswrapper and card? if i pass like this :title="item", it shows in vuedevtools, but in slots.default().map((tab) => tab.props?.title) shows symbol fragment and no props. I am passing props like this

  • @nathnolt
    @nathnolt 6 месяцев назад

    Please use the element for buttons. Don't turn the element into a button.
    As this makes it not accessible, combined with making it non keyboard navigable.

  • @geld5220
    @geld5220 3 года назад +3

    is this up todate? Im really stuck on 3:56 where you rendered the tabs in a row. This is giving me error. Im using vue 3 latest vue cli.

    • @LearnVue
      @LearnVue  3 года назад +1

      Yeah - this is up to date. If you shoot over a codepen, I can try to help debug!

    • @ahmed-mansoor
      @ahmed-mansoor 3 года назад +8

      Same here. Exactly 3:56
      Nothing returns from tabTitles
      I'm using Vue 3

    • @agnemedia624
      @agnemedia624 3 года назад +1

      @@ahmed-mansoor What is a fix for "Nothing returns from tabTitles"?

  • @iimFTx
    @iimFTx 2 года назад +1

    Really nice. I was trying to add a transition between the tab contents but that unfortunately I couldnt get working. Any idea how to transition between the tab contents?

    • @LearnVue
      @LearnVue  2 года назад +1

      Hey! You should be able to wrap your dynamic component with a transition element. v3.vuejs.org/guide/transitions-enterleave.html#enter-leave-transitions Let me know if this helps!

  • @sadeepthajayathilaka3144
    @sadeepthajayathilaka3144 2 года назад

    Great work really good explanation Thanks

  • @gopal7745
    @gopal7745 8 месяцев назад

    How can we add navigation buttons in card to go to next and previous tab.
    Please provide a idea or sudo code. Thanks in advance

  • @ZynthProductions
    @ZynthProductions 3 года назад

    Thankyou for the good video!
    can you tell us the correct way how to deal with a lazy loading image component?

  • @emreyilmaz1816
    @emreyilmaz1816 2 года назад

    Awsome Video and very well explained

  • @JaimitoAleman
    @JaimitoAleman 2 года назад +1

    Why is this code so much more different than the Companion Article and Github repo?

  • @j.m.1219
    @j.m.1219 2 года назад

    Great video! I was trying to add buttons that would add/delete tabs, but don't quite understand how to make them work. Any tips?

    • @LearnVue
      @LearnVue  2 года назад

      hey! i would try creating reactive array of components, then showing that as your tabs. that might do the trick!

    • @j.m.1219
      @j.m.1219 2 года назад

      @@LearnVue It worked, thanks!

  • @Snoweuph
    @Snoweuph 2 года назад

    Is there an updated Version? I need to convert slots first to another type so that I can remove the possibility of it being undefined, though I already use an if-guard

  • @dmitriykret8938
    @dmitriykret8938 2 года назад

    how did you find out that the slot has a default() method, where can i find out other methods, for example get the slot by name? It's like a black box

  • @coderoom805
    @coderoom805 2 года назад

    Great video. I have a question, how can we make pass a slot component for the tab title.
    From
    Hello from Tab 1
    To
    Tab 1
    Hello from Tab 1

    • @LearnVue
      @LearnVue  2 года назад

      you can defined multiple slots! learnvue.co/tutorials/vue-slots-guide#named-slots

  • @mateuszmalanowski3819
    @mateuszmalanowski3819 5 месяцев назад

    Mate, there is an issue when i want to v-for Tabs component

  • @dustincintron1682
    @dustincintron1682 Год назад

    Great video but when following this with it complains about invoking slot "default" outside of the render function. Have not figured out how to resolve that

    • @patriik948
      @patriik948 Год назад +1

      I have succeeded using:
      const slots = useSlots()
      const tabTitles = ref(slots.default?.().map((item) => item.props?.title))

    • @dustincintron1682
      @dustincintron1682 Год назад +1

      @@patriik948 thank you!

  • @darwinllacuna5328
    @darwinllacuna5328 2 года назад

    what if one of the tabs required props? how did you do that?

  • @GenetessAquino-c3t
    @GenetessAquino-c3t 11 месяцев назад

    I tried to loop Tab component using v-for it returns an error -> Uncaught (in promise) TypeError: Cannot read properties of null (reading 'title')

  • @gabrielceniza
    @gabrielceniza 2 года назад

    How do I add a pre-selected tab? like content

  • @youlv8254
    @youlv8254 3 года назад

    nice, but what is mean with provide and inject fn?

  • @brunomiguelgroth
    @brunomiguelgroth 9 месяцев назад

    Thanks a lot!

  • @_emnljrz
    @_emnljrz 2 года назад

    Can you do DataTable on Nuxt3?

  • @onyedikachierugo4120
    @onyedikachierugo4120 2 года назад

    How do i make it vertical

  • @lastchancestudiosllc
    @lastchancestudiosllc 2 года назад

    PLEASE READ: For anyone getting slot undefined errors palce your script section above the template section. This fixed all errors for me.

  • @moises0991
    @moises0991 2 года назад

    Excelente video, saludos desde México

  • @augischadiegils.5109
    @augischadiegils.5109 2 года назад

    ♥️♥️♥️

  • @buncheedev5469
    @buncheedev5469 2 года назад

    👍👍👍👍👍

  • @warpig2786
    @warpig2786 2 года назад

    I didn't understood anything that was explained to me

  • @fabi7608
    @fabi7608 3 года назад +1

    I am soo glad they removed this.$children. Writing this component in litterally 4 seconds was just boring af.

  • @ornem96
    @ornem96 2 года назад

    Thanks

  • @DryadRoot
    @DryadRoot Год назад

    would be nice if you put some inputs as content of a Tab and switch between tabs.. I can't do that without loss input data when switch tabs =(