【发布时间】:2021-05-25 22:56:37
【问题描述】:
现在正在使用 vue-konva(基于 svg 的画布库)。我正在尝试为所有由 v-loop 定义的形状设置动画。在尝试使用 Konva Animation 库函数时,我收到“无法读取未定义的属性 'getNode'”错误。我假设这是因为 ref 必须具有一个特定元素并且不能在 v-for 循环内进行寻址。如何同时为所有多边形设置动画?
SVG / 画布元素:
<v-regular-polygon
v-for="el in results"
ref="hexagon"
:key="el.index"
:config="{
x: 200 * Math.abs(el.land),
y: 200,
sides: 6,
radius: 20,
fill: 'red',
stroke: 'black',
strokeWidth: 4,
}"
/>
负责动画的函数
mounted() {
this.fetchTemperature()
const vm = this
const amplitude = 100
const period = 5000
// in ms
const centerX = vm.$refs.stage.getNode().getWidth() / 2
const hexagon = this.$refs.hexagon.getNode()
// example of Konva.Animation
const anim = new Konva.Animation(function (frame) {
hexagon.setX(amplitude * Math.sin((frame.time * 2 * Math.PI) / period) + centerX)
}, hexagon.getLayer())
anim.start()
},
【问题讨论】:
标签: vue.js animation svg nuxt.js konva