Skip to content

Using two-lists with vuex causes TypeError. #34

Open
@AnoRebel

Description

@AnoRebel

I use the latest Vue 3(3.0.11) and Vuex 4(4.0.0).
Sorry, couldnt create a quick one. But below is the basic of the component and some of its scripts.

The Component:

<div>
	  <draggable
	        v-model="tempList"
	        :component-data="{ name: 'flip-list', type: 'transition' }"
	        tag="transition-group"
	        group="tasks"
	        item-key="id"
	      >
	        <template #item="{ element }">
	          <div
	            key="item"
	            class="list-group-item min-h-[7rem] max-w-[16rem] rounded text-white text-center bg-black my-3"
	            :class="{ 'not-draggable': enabled }"
	          >
	            {{ element.name }}
	          </div>
	        </template>
	  </draggable>
</div>

The Templist value:

<script>
	const list = () => {
      if (props.list == "working") {
        return store.state.working;
      } else if (props.list == "progress") {
        return store.state.inProgress;
      } else if (props.list == "review") {
        return store.state.inReview;
      } else if (props.list == "done") {
        return store.state.done;
      } else {
        return [];
      }
    };
	const tempList = computed({
      get: () => list(),
      // set: value => store.dispatch("updateTasks", value),
      set: value => {
        // let payload = { value, type: props.list };
        // store.dispatch("updateTasks", payload);
        store.dispatch("updateTasks", value);
      },
    });
</script>

The Store:

state: {
    working: [
      { name: "A", id: 1 },
      { name: "B", id: 2 },
      { name: "C", id: 3 },
      { name: "D", id: 4 },
    ],
    inProgress: [
      { name: "E", id: 5 },
      { name: "F", id: 6 },
      { name: "G", id: 7 },
      { name: "H", id: 8 },
    ],
    inReview: [
      { name: "I", id: 9 },
      { name: "J", id: 10 },
      { name: "K", id: 11 },
    ],
    done: [
      { name: "L", id: 12 },
      { name: "M", id: 13 },
      { name: "N", id: 14 },
    ],
  },

Step by step scenario

Create an app, create a store.
Add my different lists to the store.
Call the lists in a custom draggable component i made(which is basically just a draggable that i can reuse with same values except the passed list from store)

Actual Solution

Dragging within the same list element/draggable (i.e sorting) works.
But dragging to the other list(with the same group name) breaks the whole component(becomes unresponsive).
The console logs out the error:

Uncaught TypeError: Cannot read property '3' of undefined
at insertNodeAt (htmlHelper.js:11)
at Proxy.onDragRemove (vuedraggable.js:251)
at Proxy. (vuedraggable.js:20)
at Sortable. (vuedraggable.js:28)
at dispatchEvent (sortable.esm.js:916)
at _dispatchEvent (sortable.esm.js:961)
at Sortable._onDrop (sortable.esm.js:2187)
at Sortable.handleEvent (sortable.esm.js:2269)

Expected Solution

To be able to move from one list to the other without a problem

Any help will be quite useful for I'm to both vue and vuex.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions