sagalbot / vue-sortable

A lightweight directive for reorderable drag-and-drop lists using RubaXa/Sortable
http://sagalbot.github.io/vue-sortable/
MIT License
721 stars 104 forks source link

Using with v-for #12

Closed chinchang closed 7 years ago

chinchang commented 8 years ago

Can't this be used along with v-for where items are dynamic?

callumacrae commented 8 years ago

@chinchang: did you figure this out how to do this? Currently looking to solve the same problem.

Frozire commented 8 years ago

@chinchang & @callumacrae

Please describe your problem further or include some code. I have no problem using this package and v-for.

chinchang commented 8 years ago

@Frozire Right now all examples show the usage on a static list, like so:

<ul class="list-group" v-sortable:basic>
 <li class="list-group-item">Foo</li>
 <li class="list-group-item">Bar</li>
 <li class="list-group-item">Baz</li>
</ul>

I tried it on a dynamic list made with v-for and doesn't work:

<ul class="list-group" v-sortable:basic>
 <li v-for"item in items" class="list-group-item">{{item}}</li>
</ul>
Frozire commented 8 years ago

@chinchang This works just fine for me.

There are two changes you can try - try to put the class declaration in front of the v-for, like this:

<ul class="list-group" v-sortable:basic>
 <li class="list-group-item" v-for"item in items">{{item}}</li>
</ul>

And/or wrap a div inside, to have an actual element to grab.

<ul class="list-group" v-sortable:basic>
 <li class="list-group-item" v-for"item in items">
       <div>{{item}}</div>
    </li>
</ul>
callumacrae commented 8 years ago

I ended up calling Sortable directly to make the array sortable too. I wrote an article about it: http://macr.ae/article/vue-sortable.html

chinchang commented 8 years ago

@callumacrae gr8 👍 Thanks!

David-Desmaisons commented 8 years ago

@callumacrae, @chinchang You can also use this library: Vue.Draggable It handles synchronization with list automatically both in Vue 1 (directive) amd Vue 2 (component). Disclaimer: I am the author.

sagalbot commented 7 years ago

@David-Desmaisons nice work on your library! I may end up linking to yours directly - maintaining vue-select keeps me pretty occupied, not sure I have time to maintain both on my own.