Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot read property 'element' of null when using vue component #189

Open
lu-roth opened this issue Oct 18, 2022 · 4 comments
Open

Cannot read property 'element' of null when using vue component #189

lu-roth opened this issue Oct 18, 2022 · 4 comments

Comments

@lu-roth
Copy link

lu-roth commented Oct 18, 2022

The same error occured within Vue.Draggabel for vue 2 as you can see in this issue:

SortableJS/Vue.Draggable#647

It was fixed in Version 2.22.0 but seem to appear in version 4.1 for vue3.

When using a Vue component inside the template tag, an error occurs when dragging the elements which says
Cannot read property 'element' of null

This won't work:

   <draggable
        class="draggable"
        :list="components"
        item-key="uuid"
        group="shared"
        animation="300"
        :key="components.length"
    >
      <template #item="{element}">
        <ZrmRow :isActive="chosenElement && chosenElement.uuid === element.uuid" :zrmComponent="element"/>
      </template>

But wrapped with a single div this does work:

 <draggable
       class="draggable"
       :list="components"
       item-key="uuid"
       group="shared"
       animation="300"
       :key="components.length"
   >
     <template #item="{element}">
       <div>
       <ZrmRow :isActive="chosenElement && chosenElement.uuid === element.uuid" :zrmComponent="element"/>
       </div>
     </template>

The error occurs in vuedraggable.js:
this.context seems to be null

 onDragStart(evt) {
      this.context = this.getUnderlyingVm(evt.item);
      evt.item._underlying_vm_ = this.clone(this.context.element);
      draggingElement = evt.item;
    },

System info
macOS 12.3.1
Node v18.1.0
npm 8.8.0

Packages
vue 3.2.37
vuedraggable 4.1.0

Builder
vite 2.9.12
@vitejs/plugin-vue 2.3.3
typescript 4.7.4
vue-tsc 0.38.3

Browser
Chrome 106.0.5249.103

@Androphin
Copy link

This is relevant #46

@mreduar
Copy link

mreduar commented Mar 21, 2024

This is still happening and I can't have an extra div because it is a table and everything is packed into one element. @lu-roth Have you found another solution?

@rohini-mothe-maersk
Copy link

Any solution ?

@andi-b
Copy link

andi-b commented Jun 24, 2024

I manage to resolve the issue by making sure the child component is imported. It was previously imported as a global component via defineAsyncComponent, which meant it wasn't being loaded in time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants