npm install vue-konva konva --save
使用and安装 vue-konva 和 konva 和画布npm install canvas --save
。在具有以下内容的文件夹下
vuekonva.js
创建:plugins
import Vue from 'vue'
import VueKonva from 'vue-konva'
Vue.use(VueKonva)
添加
plugins: [ "~/plugins/vuekonva"],
下nuxt.config.js
我尝试添加下
nuxt-config.js
但仍然没有运气:
build: {
standalone: true
},
- 在文件夹下创建了一个页面
pages
并从文档中添加了代码:
<template>
<div>
<v-stage ref="stage" :config="stageSize">
<v-layer>
<v-text :config="{ text: 'Some text on canvas', fontSize: 15 }" />
<v-rect
:config="{
x: 20,
y: 50,
width: 100,
height: 100,
fill: 'red',
shadowBlur: 10,
}"
/>
<v-circle
:config="{
x: 200,
y: 100,
radius: 50,
fill: 'green',
}"
/>
<v-line
:config="{
x: 20,
y: 200,
points: [0, 0, 100, 0, 100, 100],
tension: 0.5,
closed: true,
stroke: 'black',
fillLinearGradientStartPoint: { x: -50, y: -50 },
fillLinearGradientEndPoint: { x: 50, y: 50 },
fillLinearGradientColorStops: [0, 'red', 1, 'yellow'],
}"
/>
</v-layer>
<v-layer ref="dragLayer" />
</v-stage>
</div>
</template>
<script>
export default {
data () {
return {
stageSize: {
width,
height
}
}
},
mounted () {
if (process.browser) {
this.stageSize.width = window.innerWidth
this.stageSize.height = window.innerHeight
}
}
}
</script>
我得到错误:
Must use import to load ES Module:
我试过没有插件,它抛出了错误:
vue.runtime.esm.js:620 [Vue warn]: Unknown custom element: <v-stage> - did you register the component correctly? For recursive components, make sure to provide the "name" option.
found in
不明白是什么问题请帮忙。