HTML5 canvas 箭头教程
要使用 Konva
创建一个箭头形状,我们可以实例化一个 Konva.Arrow()
对象。
有关所有属性和方法的完整列表,请参见 箭头 API 参考。
- Vanilla
- React
- Vue
import Konva from 'konva'; const stage = new Konva.Stage({ container: 'container', width: window.innerWidth, height: window.innerHeight }); const layer = new Konva.Layer(); stage.add(layer); const arrow = new Konva.Arrow({ x: stage.width() / 4, y: stage.height() / 4, points: [0, 0, 100, 100], pointerLength: 20, pointerWidth: 20, fill: 'black', stroke: 'black', strokeWidth: 4 }); layer.add(arrow);
import { Stage, Layer, Arrow } from 'react-konva'; const App = () => { return ( <Stage width={window.innerWidth} height={window.innerHeight}> <Layer> <Arrow x={window.innerWidth / 4} y={window.innerHeight / 4} points={[0, 0, 100, 100]} pointerLength={20} pointerWidth={20} fill="black" stroke="black" strokeWidth={4} /> </Layer> </Stage> ); }; export default App;
<template> <v-stage :config="stageSize"> <v-layer> <v-arrow :config="arrowConfig" /> </v-layer> </v-stage> </template> <script setup> const stageSize = { width: window.innerWidth, height: window.innerHeight }; const arrowConfig = { x: window.innerWidth / 4, y: window.innerHeight / 4, points: [0, 0, 100, 100], pointerLength: 20, pointerWidth: 20, fill: 'black', stroke: 'black', strokeWidth: 4 }; </script>