can-vue
Vue plugin for HTML5 Canvas + Vue.js, nice and straightforward. Built on Konva.
Getting Started
npm i can-vue
Register the plugin:
Vue // instantiate your Vue instance after registering // ...options
Then, in a single-file component:
<!-- your canvas content here! -->
You can then add shapes from Konva inside can-vue
with draw-shape
and some props:
Properties can be reactive:
and/or percentages of the canvas space:
Component API
can-vue
Wrapper for can-vue
instance. Creates a div with classes can-vue
and wrapper
which wrap a canvas element and Vue slot.
Props
Name | Type | Default Value | Description |
---|---|---|---|
height |
String, Number | -1 | Height in px of the canvas. Defaults to full height of containing div if -1. |
width |
String, Number | -1 | Width in px of the canvas. Defaults to full width of containing div if -1. |
draw-shape
Wrapper for a single Konva shape.
Props
Name | Type | Default Value | Description |
---|---|---|---|
fill |
String | blue |
Fill color of this shape. |
height |
String, Number | 100 |
Height in pixels of the shape. Also accepts percentage of height of canvas. (example "50%" ) |
opacity |
String, Number | 1 |
Opacity of the shape. |
shape |
String | Rect |
Konva shape to render. Works with Rect and Circle currently. |
width |
String, Number | 100 | Width in pixels of the shape. Also accepts percentage of height of canvas (example "50%" ) |
x |
String, Number | 0 | X coordinate in pixels. Also accepts percentage of width of canvas (example "50%" ) |
y |
String, Number | 0 | Y coordinate in pixels. Also accepts percentage of height of canvas (example "50%" ) |
vue-konva?
What aboutVue-Konva is great, but it's a bit more complicated than can-vue in order to support Konva's full feature set. I was looking for a simple, reactive canvas framework for Vue and, since Vue-Konva isn't reactive, made a quick version of my own.