Alfred-Skyblue / vue-draggable-plus

Universal Drag-and-Drop Component Supporting both Vue 3 and Vue 2
https://vue-draggable-plus.pages.dev/en/
MIT License
3.19k stars 135 forks source link

Drag and drop report JSON conversion error in production environment #48

Closed wenyongda closed 11 months ago

wenyongda commented 1 year ago

There is no problem with using it in the development environment. But I will report Error when I pack and deploy to the production environment. Converting circular structure to JSON --> starting at object with constructor 'Object' image image But the function is good.

Alfred-Skyblue commented 11 months ago

Due to the fact that your object structure does not support JSON serialization, you can pass a custom cloning function to implement your own cloning functionality.

import { cloneDeep } from 'lodash-es'

useDraggable(el, list, {
  clone: cloneDeep
})
luveqz commented 3 months ago

In my case, I had stored my list on a Pinia store, so it was enough for me to use toRaw():

import { toRaw } from 'vue'

useDraggable(el, list, {
  clone: toRaw
})