Vue.Draggable: Cannot read property 'element' of null when using vue component
Wrapping a div
works while wrapping any vue component leads to an error for me. This code is within a nested tree of vue components of which one of the parents also uses draggable (without any issue there).
<draggable
:list="items"
tag="v-layout"
class="row wrap fill-height justify-space-around align-center"
ghost-class="draggable__ghost-class"
:group="{ name: 'actions' }"
>
<v-flex v-for="(action, i) in items" :key="i" class="action-plan__action__row__edit dropitem" xs4>
<!-- LEADS TO ERROR: <v-card style="height: 100px; width: 100px; background: green"></v-card> -->
<div style="height: 100px; width: 100px; background: green"></div>
</v-flex>
</draggable>
changing the div
to a vue component like v-card
results in an Cannot read property 'element' of null
error when starting to drag.
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 2
- Comments: 15 (5 by maintainers)
Commits related to this issue
- Solution for issue #647 — committed to SortableJS/Vue.Draggable by David-Desmaisons 5 years ago
My colleague found a fix, by simply forcing a Vue rerendering when the amount of children change. This is achievemed by supplying a
:key
to the draggable.<draggable :list="myArray" :key="myArray.length"></draggable>
Does this work for you as well?
I noticed that the
:key
thingy was also applied to the<div>
in my previous post, which is why I thought that thediv
itself fixed some of my cases.Edit: In your case that would be
I’ve had the same issue with this error popping up when reordering nested properties. I can confirm that wrapping my Vue component in a
<div>
fixed the error.So for example, the following HTML code:
had to be replaced by:
Could you create a jsfiddle?