K
K
Konstantin Malyarov2018-05-30 23:58:53
Vue.js
Konstantin Malyarov, 2018-05-30 23:58:53

How to properly implement drag and drop?

There is a library .
There is a list of operations:

<draggable v-model="operations" :options="{group:'operations'}">
                            <div v-for="operation in operations" :key="operation.id" class="border rounded"
                                 style="margin: 1px">
                                Дата: <b>{>operation.date_operation<}</b>
                                Фамилия: <b>{>operation.last_name<}</b>
                                <br>Диагноз: <b>{>operation.diagnosis<}</b>
                                <br>Название операции: <b>{>operation.operation_name<}</b>
                            </div>
                        </draggable>

There are dates with operating:
<b-tabs>
                            <b-tab v-for="(rooms, day) in period" :title="day">
                                <div v-for="room in rooms">
                                    <draggable v-model="room" :options="{group:'operations'}" class="bg-dark"
                                               style="height: 2.5px; padding: 5px; margin: 1px">
                                        <div v-for="operation in room">
                                            {>operation<}
                                        </div>
                                    </draggable>
                                </div>
                            </b-tab>
                        </b-tabs>

When dragging, the item disappears.
Before:
5b0f103e2ae14165133149.png
After:
5b0f104f08e8f915083746.png
There is a suspicion that there are problems with this section of code:
<div v-for="operation in room">
                                            {>operation<}
                                        </div>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2018-05-31
@Konstantin18ko

There is a suspicion that...

No need to suspect - you need to open the console and see what's going on there. Namely, you should have received a warning that the template was compiled with an error: "You are binding v-model directly to a v-for iteration alias. This will not be able to modify the v-for source array because... blah blah blah".
Add an index (eg room_index) to v-for="room in rooms".
And replace v-model="room"with v-model="period[day][room_index]".

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question