Vue Konva is a JavaScript library that provides declarative and reactive bindings for the Konva Framework, enabling complex canvas graphics within Vue.js applications. It leverages Vue's component system to render Konva stages, layers, and shapes, abstracting away direct DOM manipulation. The current stable version, 3.4.0, primarily supports Vue 3 and Konva >7, with `vue-konva@2` maintained for Vue 2 compatibility. While there's no fixed release cadence, updates generally align with advancements in Vue.js and Konva.js to ensure continued integration. Its key differentiator is simplifying canvas interaction by mapping Konva objects to Vue components prefixed with 'v-', allowing developers to define canvas elements and their properties reactively using Vue's familiar template syntax and data flow, making complex canvas animations and interactions more manageable.
npm install vue-konvaVerified import paths — ran on the pinned version, not inferred.
This example demonstrates how to set up `vue-konva` with a Vue 3 application, globally registering the plugin, and then rendering a simple red circle and a blue rectangle on a canvas. It shows how to pass Konva properties via the `config` prop and make shapes draggable.
For Vue 2 projects, use `npm install vue-konva@2 konva --save`. For Vue 3 projects, use `npm install vue-konva konva --save`.
Always wrap Konva properties in a `:config` prop object, e.g., `<v-circle :config="{ x: 100, fill: 'red' }"></v-circle>`.Use `this.$refs.myRef.getNode()` (Options API) or `myRef.value.getNode()` (Composition API) to get the Konva instance.
For consistent reactivity, prefer updating the `config` prop directly rather than mutating Konva nodes obtained via `getNode()`. If direct mutation is necessary, consider implementing 'strict mode' as described in `vue-konva` documentation or manually synchronizing changes back to your `config` data.
Ensure `import VueKonva from 'vue-konva';` and `app.use(VueKonva);` (for Vue 3) are present in your main application entry file (e.g., `main.ts` or `main.js`).
Ensure the component is mounted before accessing its ref and calling `getNode()`, typically within `onMounted` (Composition API) or `mounted` (Options API) lifecycle hooks. Also, confirm the ref is correctly attached to a `v-` component.
Place all Konva-specific properties inside a single `config` object and bind it to the `v-` component using `:config`. For example, `<v-circle :config="{ x: 100, y: 100, fill: 'red' }"></v-circle>`.Ensure `v-stage` contains `v-layer` components, and `v-layer` or `v-group` components contain your specific Konva shapes (`v-circle`, `v-rect`, etc.). Correct hierarchy is `<v-stage><v-layer><v-shape/></v-layer></v-stage>`.