Konvajs + Vuejs如何在vue中访问舞台宽度

问题描述 投票:0回答:1

当使用不带vue的Konva时,我可以像这样访问和修改舞台宽度:

var stage = new Konva.Stage({
        container: 'container',
        width: stageWidth,
        height: stageHeight
      });

stage.width(100); //good

我不访问舞台对象,并且通过扩展使用vuejs设置其宽度:

<template>
  <v-stage :config="configKonva">
    <v-layer>
      <v-circle :config="configCircle"></v-circle>
    </v-layer>
  </v-stage>
</template>
<script>


export default {
 methods: {
  setWidth(width) {
   //here I want to access stage and set it's width
 }
}
}

</script>
vue.js konvajs
1个回答
0
投票
您需要为v-stage添加“参考”。之后,您将直接访问v-stage组件实例。因此,之后您可以调用其方法getStage()

<v-stage :config="configKonva" ref="konva"> ... export default { methods: { setWidth(width) { this.$refs.konva.getStage().width(640); } }

© www.soinside.com 2019 - 2024. All rights reserved.