Vue Konva

3.4.0 · active · verified Tue Apr 21

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.

Common errors

Warnings

Install

Imports

Quickstart

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.

import { createApp } from 'vue';
import App from './App.vue';
import VueKonva from 'vue-konva';

const app = createApp(App);
app.use(VueKonva);
app.mount('#app');

// App.vue
/*
<template>
  <v-stage :config="configKonva">
    <v-layer>
      <v-circle :config="configCircle"></v-circle>
      <v-rect :config="configRect"></v-rect>
    </v-layer>
  </v-stage>
</template>

<script setup lang="ts">
import { ref } from 'vue';

const configKonva = ref({
  width: 400,
  height: 300
});

const configCircle = ref({
  x: 100,
  y: 100,
  radius: 50,
  fill: "red",
  stroke: "black",
  strokeWidth: 4,
  draggable: true
});

const configRect = ref({
  x: 200,
  y: 150,
  width: 80,
  height: 60,
  fill: "blue",
  stroke: "darkblue",
  strokeWidth: 3,
  draggable: true
});
</script>
*/

view raw JSON →