vue.js - Konvajs + Vuejs 如何在 vue 中访问舞台宽度
问题描述
在没有 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>
解决方案
您需要为v-stage
. 之后,您将直接访问v-stage
组件实例。所以在那之后你可以调用它的方法getStage()
。
<v-stage :config="configKonva" ref="konva">
...
export default {
methods: {
setWidth(width) {
this.$refs.konva.getStage().width(640);
}
}
推荐阅读
- javascript - 在 powerschool 中创建自定义页面
- java - java.lang.ArrayIndexOutOfBoundsException:长度=3;指数=-1
- swift - metadata?.downloadURL()?.absoluteString
- r - 在 R 中正确定义类的成员和不变量
- c# - .Net - 如何在并行批处理或多个实例中处理大量 MongoDB 文档
- java - 使用 Webstream 中的 JAAD 播放 AAC
- html - 本地主机打开html文件
- c# - OpenIdConnectProtocolValidationContext.Nonce 为空
- c++ - htonl出现分段错误
- windows - 如何使用 fpdf 在表格列中显示数据