konva-demo/src/views/shapes/图形/index.vue

39 lines
650 B
Vue
Raw Normal View History

2024-07-11 10:03:32 +08:00
<template>
<div id="container"></div>
</template>
<script setup lang="ts">
import { useWindowSize } from '@vueuse/core';
import Konva from 'konva/lib/index';
import { onMounted } from 'vue';
const { width, height } = useWindowSize();
const initial = () => {
const stage = new Konva.Stage({
container: 'container',
width: width.value,
height: height.value,
});
2024-07-11 10:42:09 +08:00
const layer = new Konva.Layer({ draggable: true });
2024-07-11 10:03:32 +08:00
2024-07-11 10:42:09 +08:00
layer.add(
new Konva.RegularPolygon({
x: 100,
y: 150,
sides: 6,
radius: 70,
fill: 'red',
stroke: 'black',
strokeWidth: 4,
}),
);
2024-07-11 10:03:32 +08:00
stage.add(layer);
};
onMounted(() => {
initial();
});
</script>