vue-grid-layout
vue-grid-layout copied to clipboard
fix: resolve the wrong actual dragging item which drag from outside
Situation:
When I use the feature of dragging item from outside, I find the dragging item can't place in some specific position.
After researching, I found that the grid-item I got by the below codes is another existing grid-item.
let index = this.layout.findIndex(item => item.i === 'drop');
let el = this.$refs.gridlayout.$children[index];
And it leads to the wrong result of calcXY() which based on w and h of the unexpected grid-item.
Root case:
The reason is mismatching between layout sort and $refs.gridlayout.$children sort. So we may get unexpected gird-item by using index of layout.
Refer: https://v2.vuejs.org/v2/api/index.html#vm-children
Solution:
Instead of layout, get grid-item by $refs.gridlayout.$children directly. Like below:
let el = this.$refs.gridlayout.$children.find(el => el.i === 'drop' && !el.$el.classList.contains('vue-grid-placeholder'))
Ps: i of vue-grid-placeholder also is 'drop'