Konvajs/Vue-konva 添加 Text/Label 到每个创建的矩形

Konvajs/Vue-konva add Text/Label to each of the created Rect shape

我在 Vuejs/Nuxt 应用程序中使用 Konvajs/Vue-Konva。使用 Konva 我在 运行 时间动态创建 Rect 形状。我想知道是否有办法在每个形状中添加 Text/Label 。我想为每个 Shape 添加一个名称,以便分别识别每个 Shape

我已经在 CodeSandBox 中添加了我的代码示例。

谁能告诉我如何将 Text/Label 添加到使用 Vue-Konva

创建的每个 Rect/Shape

您可以使用Konva.Group将多个形状组织成结构。

<v-group
  v-for="rec in nodeArray"
  :key="'node' + rec.id"
  :config="{
    x: Math.min(rec.startPointX, rec.startPointX + rec.width),
    y: Math.min(rec.startPointY, rec.startPointY + rec.height),
  }"
  @click="showEventInfoModal(rec.name)"
>
  <v-rect
    :key="'node' + rec.id"
    :config="{
      width: Math.abs(rec.width),
      height: Math.abs(rec.height),
      fill: 'rgb(0,0,0,0)',
      stroke: 'black',
      strokeWidth: 3,
      draggable: true,
    }"
  />
  <v-text
    :config="{
      text: rec.name,
    }"
  />
</v-group>