Adding Drag and Drop to Your Vue 3 Project

แชร์
ฝัง
  • เผยแพร่เมื่อ 28 ส.ค. 2024
  • Adding drag and drop functionality is a great way to make your apps feel more natural and user friendly. In this tutorial, learn how to include the HTML Drag and Drop Project into your Vue 3 Vite App.
    LINKS
    Companion Article w/ Code - learnvue.co/20...
    Vite Tutorial - www.youtube.co....
    HTML Drag and Drop API - developer.mozi...
    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...

ความคิดเห็น • 78

  • @lehlohonolomotsoeneng6672
    @lehlohonolomotsoeneng6672 3 หลายเดือนก่อน +1

    After two libraries and more than 2 hours and not getting it right, I watched your tutorial and got it right and my application works like a charm. Thank you!

  • @ashemukisa4727
    @ashemukisa4727 3 ปีที่แล้ว +29

    The tutorial is clear and builds the solution from first principles which is a great way for me modify it. Thanks Matt.

    • @LearnVue
      @LearnVue  3 ปีที่แล้ว

      Glad to hear - that's always my goal with these videos!

  • @astrosoup
    @astrosoup 3 ปีที่แล้ว +48

    This was so well done. High quality content and so helpful, thank you

    • @LearnVue
      @LearnVue  3 ปีที่แล้ว +1

      thanks for watching!

  • @PrashantNirgun
    @PrashantNirgun 2 ปีที่แล้ว +15

    This tutorials is very good it uses Vanila Js instead of additional libraries just few bytes of code and that's all. Good work keep it up.

  • @tomparke2407
    @tomparke2407 2 ปีที่แล้ว +4

    Always appreciate tutorials utilising browser api standards over a hot library. People will still be able to use this video in 2 years.

    • @casmironyeka1104
      @casmironyeka1104 20 วันที่ผ่านมา +1

      Two years later and this video just saved me right now! 😂

  • @DaneVideo
    @DaneVideo 3 ปีที่แล้ว +2

    This video helped me get drag and drop working in my app in less than an hour

  • @chamberlainpi
    @chamberlainpi 2 ปีที่แล้ว +8

    Why nuke the “setup” attribute from the get go? Are there any reasons this couldn’t have been accomplished with the new setup syntax sugar?

  • @perfect.stealth
    @perfect.stealth 2 ปีที่แล้ว +1

    I just found this channel. I am not disappointed. Thanks for sharing!

  • @araputrevor5103
    @araputrevor5103 20 วันที่ผ่านมา

    Awesome dude, you made it so easy for me to get started.

  • @00AnnaEszter
    @00AnnaEszter 2 ปีที่แล้ว +2

    Thank you for the this great beginners guide! I would love to see a second part where the inner values of the draggable elements are changing: like if C is a basket and A and B are elements that we can add to the basket so the value of C is growing and the number (on) of A and B are reducing.

  • @titusayyasamy3035
    @titusayyasamy3035 2 ปีที่แล้ว +2

    this explanation is outstanding

  • @_rtdp_
    @_rtdp_ ปีที่แล้ว

    I came here from your web app. You web app is awesome dude... You just earned a subscriber...

  • @mikehillbilly4079
    @mikehillbilly4079 ปีที่แล้ว +1

    Love this concise, direct and clear tutorial. Very professional

  • @rashadrivera100
    @rashadrivera100 3 ปีที่แล้ว +4

    Very nice! Appreciate how you layout all the intricate details.

    • @LearnVue
      @LearnVue  3 ปีที่แล้ว

      Thank you so much! I had a lot of fun making this video.

  • @codybontecou
    @codybontecou 2 ปีที่แล้ว +6

    For anyone running into the error `Uncaught TypeError: Cannot set properties of undefined (setting 'list')`,
    I fixed this by setting my item ID's to strings.
    const items = ref([
    { id: '0', title: 'Item A', list: 1 },
    { id: '1', title: 'Item B', list: 1 },
    { id: '2', title: 'Item C', list: 2 },
    ])

  • @herisetrarazafiarison4563
    @herisetrarazafiarison4563 2 ปีที่แล้ว +1

    Very clear and straight video, thank you

  • @PopescuMarian
    @PopescuMarian 3 ปีที่แล้ว +3

    great, finally some good vue tutorials

    • @LearnVue
      @LearnVue  3 ปีที่แล้ว +1

      More to come!

  • @MattMcT
    @MattMcT 2 ปีที่แล้ว

    Coming through again, my man! Hope you are well and thank you as always for your solid vid vibe!

  • @casmironyeka1104
    @casmironyeka1104 20 วันที่ผ่านมา

    Thanks so much for this.

  • @paul2DD
    @paul2DD ปีที่แล้ว +3

    dataTransfer stores Strings, for those who get into error "Uncaught TypeError: item is undefined", you must convert itemId to string -> const item = items.value.find((item) => item.id === parseInt(itemId))

  • @lawrencesmith9059
    @lawrencesmith9059 3 หลายเดือนก่อน

    A truly great video.

  • @user-kb2sc7ll4r
    @user-kb2sc7ll4r 2 ปีที่แล้ว

    Your video is so intuitive and clear, thank you.

  • @yoanestradablanco1608
    @yoanestradablanco1608 2 ปีที่แล้ว +1

    good content and successes my bro

  • @helmin9469
    @helmin9469 2 ปีที่แล้ว

    thank you, got it on the first try following your tutorial

  • @MrBalobba
    @MrBalobba 3 ปีที่แล้ว +2

    I love vue and I love this channel. Keep up the good work!

  • @vinothrenga1
    @vinothrenga1 2 ปีที่แล้ว +1

    Awesome, thanks dude.😊

  • @webdev1943
    @webdev1943 2 ปีที่แล้ว +1

    thank you

  • @dibbyo456
    @dibbyo456 2 ปีที่แล้ว +1

    Another high quality content. 👌

  • @vitordossantosbrandao8325
    @vitordossantosbrandao8325 10 หลายเดือนก่อน

    Really really helpful. Thank you very much!

  • @AlphaWatt
    @AlphaWatt 2 ปีที่แล้ว

    Excellent video. Super clear instruction and very helpful info. Thanks!

  • @ricardovergara9852
    @ricardovergara9852 ปีที่แล้ว

    Great video! You make it look easy to follow! thanks

  • @sammieboy793
    @sammieboy793 2 ปีที่แล้ว +3

    Is there a way to figure out how to drag & drop to change the order of the items in the list?

    • @AchariPhp
      @AchariPhp 2 ปีที่แล้ว +1

      I'm also looking for this solution.. did you fixed this one Sam.

    • @thefeymesaleng
      @thefeymesaleng 2 ปีที่แล้ว +1

      @@AchariPhp 2 months late, but the usual way of doing it is having another elements inside the item itself and positioned it at the top and bottom that take a drag/drop event/function. So if a dragged item dropped on top positioned element of an item, it will run a function that inserting the dragged item to one index behind the item, and the same for the bottom element of an item, but with the add one index.

  • @AgnesPalit_adirgapalit
    @AgnesPalit_adirgapalit 2 ปีที่แล้ว +2

    Hi Do you have a way so the object that we drag and drop only stick into axis x or y (move horisontaly/vertically only)?

  • @thomasderidder608
    @thomasderidder608 2 ปีที่แล้ว

    It worked perfectly, thanks a lot!

  • @SusanthCom
    @SusanthCom 3 ปีที่แล้ว +2

    Good job ❤️❤️❤️. Thanks 👍

    • @LearnVue
      @LearnVue  3 ปีที่แล้ว +1

      Thank you so much for watching 😊

  • @stevensadler1685
    @stevensadler1685 3 ปีที่แล้ว +2

    For me, dragging and dropping an item is moving it to the new group, but there is no semi-transparent version of the item following the mouse pointer. Instead my mouse pointer turns into a circle with a line through it - the "no" symbol. Any idea what I missed?

    • @LearnVue
      @LearnVue  3 ปีที่แล้ว +1

      hmm i haven't seen that before. just from my experience, it could be one of the settings in the drag and drop api - since it is pretty specific on the requirements needed. so just make sure that all of those match. or it could maybe it a browser-specific issue.

  • @markg5986
    @markg5986 ปีที่แล้ว

    Great tutorial. Thanks!

  • @dfeverx-en
    @dfeverx-en 3 ปีที่แล้ว +2

    super helpful

    • @LearnVue
      @LearnVue  3 ปีที่แล้ว

      glad you think so!

  • @itxhaseeb5794
    @itxhaseeb5794 11 หลายเดือนก่อน

    Excellent Work

  • @cozilic
    @cozilic 3 ปีที่แล้ว

    If you are doing this via a Laravel blade view, don't forget to include the props
    export default {
    props:['itemID'],
    setup() {....
    thats what i had to do anyways.

  • @svenyboyyt2304
    @svenyboyyt2304 10 หลายเดือนก่อน

    Why did you not use script setup?

  • @jntaca
    @jntaca 3 ปีที่แล้ว +2

    You're the best.

    • @LearnVue
      @LearnVue  3 ปีที่แล้ว +1

      thanks!

  • @JORGEMARTINEZ-ho4wp
    @JORGEMARTINEZ-ho4wp 3 ปีที่แล้ว +3

    nice

  • @max_nostradamus
    @max_nostradamus 4 หลายเดือนก่อน

    Why remove "setup" from the script tag? Its makes vue 3 so much more readable...

  • @dgenerationx5220
    @dgenerationx5220 ปีที่แล้ว

    Can we drop the clone of the elements dragged in vue

  • @kanundash
    @kanundash 3 ปีที่แล้ว +2

    greate video

  • @user-jt5vm3mi1w
    @user-jt5vm3mi1w ปีที่แล้ว

    Good tutorial

  • @oleksiizelenko9357
    @oleksiizelenko9357 3 ปีที่แล้ว +2

    super

  • @sebastianjung3168
    @sebastianjung3168 ปีที่แล้ว

    would be great if these video would have been mobile friendly 🤗

  • @siemaneczko9850
    @siemaneczko9850 ปีที่แล้ว

    Will it work on vue2?

  • @ShadowVipers
    @ShadowVipers 2 ปีที่แล้ว +1

    Oh man, I knew about those events, but never realized what they were for.... I ended up building the drag & drop logic from scratch using drag classes and setting it's position based on the cursor pos.... The facepalm is real...

  • @Imaginativeone_DF
    @Imaginativeone_DF 2 ปีที่แล้ว

    How would I apply this tutorial to a hierarchical tree?

    • @LearnVue
      @LearnVue  2 ปีที่แล้ว

      it should be a pretty similar concept, but with nested drop zones.
      the draggable should ondrop event would still trigger with the id, which you can use to move data around.
      i haven’t tested this on my computer, but the two things i’d look out for are:
      1. making sure events don’t propagate up the component chain in the case of nested drop zones
      2. the data structure would be a more complex than the tutorial

  • @wahomemutahi1008
    @wahomemutahi1008 ปีที่แล้ว

    Thaaaaaaaaaaaaankyoooooooou

  • @pedroismael17
    @pedroismael17 2 ปีที่แล้ว

    for mobile device no works, can any help me?? :(

    • @gastonmorales3619
      @gastonmorales3619 2 ปีที่แล้ว +1

      You'd need to use another API, for mobile devices is not working in this case

    • @pedroismael17
      @pedroismael17 2 ปีที่แล้ว

      @@gastonmorales3619 i resolved! :D

    • @gastonmorales3619
      @gastonmorales3619 2 ปีที่แล้ว

      Could You share the solution in this reply?

    • @pedroismael17
      @pedroismael17 2 ปีที่แล้ว +1

      Yes, give me a few hours and I'll share it

    • @SusanthCom
      @SusanthCom 2 ปีที่แล้ว +1

      @@pedroismael17 Any link please

  • @bibhasash7371
    @bibhasash7371 ปีที่แล้ว

    best

  • @kafir5801
    @kafir5801 6 หลายเดือนก่อน

    Strange this code does not work on Firefox, Opera and Crhome (no errors)

  • @user-gy3rm9hf7m
    @user-gy3rm9hf7m 3 ปีที่แล้ว

    Uncaught TypeError: Cannot read property 'dataTransfer' of undefined
    at Proxy.onDrop (App.vue:34)
    setup() {
    const items = ref([
    {id: 0, title: 'Item A', list: 1},
    {id: 1, title: 'Item B', list: 1},
    {id: 2, title: 'Item C', list: 2},
    {id: 3, title: 'Item D', list: 2},
    ])
    const getList = (list) => {
    return items.value.filter((item) => item.list == list)
    }
    const startDrag=(event,item)=>{
    console.log(item)
    event.dataTransfer.dropEffect='move'
    event.dataTransfer.effectAllowed='move'
    event.dataTransfer.setData('itemId',item.id)
    }
    const onDrop=(event,list)=>{
    const itemId=event.dataTransfer.getData('itemId')
    const item=items.value.find((item)=> item.id ===itemId)
    item.list=list
    }
    return {
    getList,startDrag,onDrop
    }
    }
    where is mistake?

    • @fermevc
      @fermevc 2 ปีที่แล้ว

      When you call startDrag function from the template, you need to put "$event", but I'm just guessing because you didn't share all the code...

  • @MohdSolihin
    @MohdSolihin 2 ปีที่แล้ว +1

    thank you