I
I
ilovemaryjane2018-11-23 15:48:38
JavaScript
ilovemaryjane, 2018-11-23 15:48:38

Weird data mutation problem, how to solve (updated with example)?

Some strange mutation is happening - https://codesandbox.io/s/n0o76nmz4
The problem is localized on line 60-62 in the HelloWorld.vue file
When scrolling down, there should be an update this.translateYto the value ticker
Everything works correctly if I output to the console this.translateY - ticker.
But if I do this.translateY = this.translateY - tickerthat, there is a multiple increase in the value, with each scroll, the value adds itself, and only the scroll change should change - the ticker.
What it is?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
X
xmoonlight, 2018-11-23
@ilovemaryjane

Most likely, the recursion call is due to this and the variable changes value like a snowball. Try using an explicit increment using the modulus of the difference between the current and previous event value.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question