How to change the zIndex of nodes with Vue?
How to change the zIndex and reorder components in vue-konva
?
When you are working with Konva
directly, you have many methods to change the order of nodes like node.zIndex(5)
, node.moveToTop()
, etc. See the Layering Tutorial for more details.
However, when working with Vue, it's recommended to follow Vue's declarative approach instead of using these imperative methods.
vue-konva
follows the order of the nodes exactly as you describe them in your <template>
. Instead of changing the zIndex
manually, you should update your app's data so that the components in your <template>
maintain the correct order.
The demo shows how to:
- Create an array of circle shapes with random positions and colors
- Handle drag events to update the visual order of shapes
- Maintain the correct stacking order by manipulating the array order
- Follow Vue's reactivity system for state management
Remember: Don't use the zIndex
property for your canvas components. Instead, rely on the order of elements in your template and data structures.
Instructions: Try to drag a circle. When you start dragging, it will automatically move to the top of the stack. This is achieved by manipulating the array of circles in our data, not by manually changing zIndex.